Parallel.ForEach VS进行AsParallel()的ForAll [英] Parallel.ForEach vs AsParallel().ForAll

查看:453
本文介绍了Parallel.ForEach VS进行AsParallel()的ForAll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大,我想处理每个对象以并行的方式。做同样的同步通常需要一个简单的的foreach。

I have a huge collection which I would like to process each of the object in a parallel fashion. Doing the same synchronously typically involves a simple "foreach".

只是想知道,在我的情况,即,无论是Parallel.ForEach或MyCollection.AsParallel()来使用的。的ForAll()。

Just wondering, what to use in my scenario i.e., either Parallel.ForEach or MyCollection.AsParallel().ForAll().

可以摆脱我使用一个VS其他利益的一些情况。

Can you shed me some light on benefits of using the one vs the other.

推荐答案

在我看来,如果你想要做的是并行化的foreach ,你应该的方式使用它的水货版本,这是 Parallel.ForEach()

The way I see it, if all you want to do is to parallelize a foreach, you should use its parallel version, which is Parallel.ForEach().

ParallelEnumerable.ForAll()是,你有一个LINQ查询后跟一个特定的情况下的foreach 和要并行他们两个。所以,你做什么,是你并行的LINQ查询中加入进行AsParallel()然后并行化的foreach 通过将其改为的ForAll()

ParallelEnumerable.ForAll() is for the specific case where you have a LINQ query followed by a foreach and you want to parallelize both of them. So, what you do is that you parallelize the LINQ query by adding AsParallel() and then you parallelize the foreach by changing it into ForAll().

这篇关于Parallel.ForEach VS进行AsParallel()的ForAll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆