I can use Parallel.ForEach or ParallelEnumerable.ForAll, so what is the difference between the two, if any?
Parallel.ForEach is tantamount to using foreach in normal code.
The ParallelEnumerable.ForAll method is effectively equivalent to List<T>.ForEach .
Both will work and work the same way, although the ForAll method requires you to use PLINQ already, since you need ParallelEnumerable . Parallel.ForEach works directly with any IEnumerable<T> .
In general, I prefer Parallel.ForEach , as ForAll sole purpose is to cause side effects. There are some drawbacks to this, as described in detail by Eric Lippert .
source share