AsParallel.ForAll vs Parallel.ForEach

前端 未结 4 1148
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 15:11

Is there any difference between the below code snippets. If so, what?

myList.AsParallel().ForAll(i => { /*DO SOMETHING*/ });

and

Pa

4条回答
  •  走了就别回头了
    2021-01-31 16:09

    Parallel.ForEach() is intended exactly for this kind of code.

    On the other hand, ForAll() is intended to be used at the end of a (possibly complex) PLINQ query.

    Because of that, I think Parallel.ForEach() is the better choice here.

    In both cases, the current thread will be used to perform the computations (along with some threads from the thread pool) and the method will return only after all processing has been completed.

提交回复
热议问题