简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM