4

I am downloading files which means that even though I had only 2 cores, it would improve performance to make more than two threads.

Does the Parallel.ForEach() only make as many threads as the amount of cores, even though I set ParallelOptions.MaxDegreeOfParallelism to a higher value?

4

1 回答 1

4

From documentation:

The MaxDegreeOfParallelism limits the number of concurrent operations run by Parallel method calls that are passed this ParallelOptions instance to the set value, if it is positive. If MaxDegreeOfParallelism is -1, then there is no limit placed on the number of concurrently running operations.

This function throw only ArgumentOutOfRangeException and type of MaxDegreeOfParalleism is int. So it means, that it can create more threads than count of cores.

I can confirm it, because I've ran a lot of xml generation processes and Task Manager shown count of processes exactly as I've set before.

于 2012-10-17T12:19:38.453 回答