c# parallel.for怎么控制并发数量啊,据说是ParallelOptions,怎么用求示例,我想要最多5个并发量
发布网友
发布时间:2022-04-13 02:58
我来回答
共1个回答
热心网友
时间:2022-04-13 04:27
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);
});