提问
C#如何进行并行任务
回答
- 最大并行书为系统CPU数
po.MaxDegreeOfParallelism = Environment.ProcessorCount;
var po = new ParallelOptions();
po.MaxDegreeOfParallelism = Environment.ProcessorCount;
try
{
Parallel.ForEach(request.Equips!, po, (equip) =>
{
//Todo;
});
}
catch (OperationCanceledException e)
{
Console.WriteLine(e.Message);
}
finally
{
tokenSource.Dispose();
}
标签:C#,ProcessorCount,Environment,如何,并行任务,MaxDegreeOfParallelism,po
From: https://www.cnblogs.com/wuhailong/p/17242343.html