Difference between Parallel.ForEach and ParallelEnumerable.ForAll

I have a set of Model classes, and I will not display each class separately for Model Model classes.

I can use Parallel.ForEach or ParallelEnumerable.ForAll , so what is the difference between the two, if any?

I can not find anything on MSDN.

+4
source share
1 answer

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 .

+5
source

Source: https://habr.com/ru/post/1484937/


All Articles