C# 使用有序c时设置DegreeofParallelism#
我得到以下错误“只能对AsParallel、ParallelEnumerable.Range或ParallelEnumerable.Repeat的结果调用Ordered” 当运行以下代码时C# 使用有序c时设置DegreeofParallelism#,c#,linq,parallel-processing,C#,Linq,Parallel Processing,我得到以下错误“只能对AsParallel、ParallelEnumerable.Range或ParallelEnumerable.Repeat的结果调用Ordered” 当运行以下代码时 myListofActions.AsParallel().WithDegreeOfParallelism(threadCount) .AsOrdered().ForAll(x => DoMyTask(x)); 这个代码很好
myListofActions.AsParallel().WithDegreeOfParallelism(threadCount)
.AsOrdered().ForAll(x => DoMyTask(x));
这个代码很好用
myListofActions.AsParallel().AsOrdered().ForAll(x => DoMyTask(x));
在这种情况下,有没有办法设置WithDegreeOfParallelism
提前感谢试试这个:
myListofActions.AsParallel()
.AsOrdered()
.WithDegreeOfParallelism(Math.Min(threadCount, Environment.ProcessorCount))
.ForAll(DoMyTask);
不完全是这样,我只是阅读了错误消息,并相应地重新安排了通话顺序。:)