Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用有序c时设置DegreeofParallelism#_C#_Linq_Parallel Processing - Fatal编程技术网

C# 使用有序c时设置DegreeofParallelism#

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)); 这个代码很好

我得到以下错误“只能对AsParallel、ParallelEnumerable.Range或ParallelEnumerable.Repeat的结果调用Ordered”

当运行以下代码时

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);

不完全是这样,我只是阅读了错误消息,并相应地重新安排了通话顺序。:)