I have a collection of Model classes and I wan't to Map each class individually to View Model classes.
I can use Parallel.ForEach
or ParallelEnumerable.ForAll
, so what is the difference between the 2, if any?
I couldn't find anything on MSDN.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With