首页 > 编程语言 >C#如何进行并行任务

C#如何进行并行任务

时间:2023-03-22 09:13:54浏览次数:38  
标签:C# ProcessorCount Environment 如何 并行任务 MaxDegreeOfParallelism po

提问

C#如何进行并行任务

回答

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

相关文章