Gets or sets the maximum degree of parallelism enabled by this ParallelOptions instance.
Assembly: mscorlib (in mscorlib.dll)
The exception that is thrown when this is set to 0 or some value less than -1.
The 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 is -1, then there is no limit placed on the number of concurrently running operations.
The setting exists predominantly to provide control for advanced usage. For example, if you know that a particular algorithm you're using won't scale beyond a certain number of cores, you can set the property to avoid wasting cycles on additional cores. Or, if you're running multiple algorithms concurrently and want to manually divide up how much of the system they could utilize, you can set a value for each.
For certain workloads, the thread pool's heuristics may be unable to determine the right number of threads to use and could end up injecting too many threads. For example, in long-running loop body iterations, the thread pool may not be able to tell the difference between reasonable progress or livelock or deadlock, and may not be able to reclaim threads added to improve performance. In this case, you can set a value to ensure that you don't use more than a reasonable number of threads.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)