开发者

How to increase concurrent parallel tasks with System.Threading.Parallel (.Net 4.0)

开发者 https://www.devze.com 2022-12-15 10:20 出处:网络
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 execut

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 开发者_如何学Gocore).

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


IF you are using Parallel.For or Parallel.ForEach you can specify a ParallelOptions object which has a property MaxDegreesOfParallelism. Unfortunately this is just a maximum limit as the name suggests, and does not provide a lower bound guarantee. For the relationsship to WithDegreeOfParallelism see this blog post.


MAY NOT - enough said. Blindy commented it correctly

0

精彩评论

暂无评论...
验证码 换一张
取 消