如何提高并发并行任务,System.Threading.Parallel(.NET 4.0) [英] How to increase concurrent parallel tasks with System.Threading.Parallel (.Net 4.0)

查看:260
本文介绍了如何提高并发并行任务,System.Threading.Parallel(.NET 4.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试用新的System.Threading.Parallel方法,如并行和foreach。

他们似乎很好地工作,但我需要一种方法来增加被执行的这8个(我有一个四核心)的并发线程数。

我知道有一种方法,我只是能找到的地方你所隐藏的那该死的属性。

吉拉德。

解决方案

报价:

  VAR的查询=从项目中source.AsParallel()。WithDegreeOfParallelism(10)
        其中,计算(项目)> 42
        选择项目;
 

在其中一个查询正在执行显著量的非受计算量限制的工作,如文件的情况下的I / O,这可能是有益的,以指定并行度大于机床上的核心数量的

来自: MSDN

I'm experimenting with the new System.Threading.Parallel methods like parallel for and foreach.

They seem to work nicely but I need a way to increase the number of concurrent threads that are executed which are 8 (I have a Quad core).

I know there is a way I just can find the place thy hidden the damn property.

Gilad.

解决方案

quote:

var query = from item in source.AsParallel().WithDegreeOfParallelism(10)
        where Compute(item) > 42
        select item;

In cases where a query is performing a significant amount of non-compute-bound work such as File I/O, it might be beneficial to specify a degree of parallelism greater than the number of cores on the machine.

from: MSDN

这篇关于如何提高并发并行任务,System.Threading.Parallel(.NET 4.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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