Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top