This is the example microsoft presents for the parallel for, and I\'d like to know how configure a maximum number of threads for this code.
// A basic m
Use MaxDegreeOfParalelism property for running the loop
Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = 2 }, ...);
You need to specify a ParallelOptions value with a MaxDegreeOfParallelism
:
For example:
Parallel.For(0, 10, new ParallelOptions { MaxDegreeOfParallelism = 4 }, count =>
{
Console.WriteLine(count);
});
I'd suggest you take a look at the ParallelOption.MaxDegreesofParellelism and pass it into the For
method