I can use Parallel.ForEach or ParallelEnumerable.ForAll, so what is the difference between the 2, if any?
Parallel.ForEach
is the equivelent to using foreach
in normal code.
The ParallelEnumerable.ForAll
method is effectively the equivelent to List<T>.ForEach
.
Both will perform and work similarly, though the ForAll
method requires you to be using PLINQ already, as you need a ParallelEnumerable
. Parallel.ForEach
works directly off any IEnumerable<T>
.
In general, I tend to prefer Parallel.ForEach
, as the sole purpose of ForAll
is to cause side effects. There are some disadvantages to this, as described in detail by Eric Lippert.