c # parallel.for how to control the number of concurrent control the amount of more than five concurrent

             Parallel.For(0,10,
                         new ParallelOptions(){MaxDegreeOfParallelism = 5},
                         (i, loopState) =>
                         {
                             System.Diagnostics.Debug.WriteLine("Start Thread={0}, i={1}", Thread.CurrentThread.ManagedThreadId, i);
 
                             Thread.Sleep(i*200);
                             Console.WriteLine("Finish Thread={0}, i={1}", Thread.CurrentThread.ManagedThreadId, i);
                         });

 

Guess you like

Origin www.cnblogs.com/zhangzhiping35/p/11058684.html