I don't think I understand the Parallel for loop.. when I try this program
Parallel.For(1, 20, i =>
{
Thread.Sleep(200);
Console.WriteLine(i);
});
it will spit out:
1
10
19
2
11
4
3
12
5
6
13
17
7
14
18
8
15
9
16
what I'm wanting to do is have a for loop threaded with a limit of 20 threads and make it print out like this, 1,2,3,4,5,6,7,8,9,10.. ect
Parallel.Forwill create as many threads as is optimal for the computer running the code (e.g. 8 threads for a quad-core hyperthreaded CPU, but only 1 thread for a simple ARM device), you cannot set an absolute number of threads, but you can place a limit with theMaxDegreeOfParallelismoption.