C#如何进行并行任务
提问
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();
}