c# - 使用 AsOrdered c# 时设置 DegreeofParallelism

标签 c# linq parallel-processing

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

运行以下代码时

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

关于c# - 使用 AsOrdered c# 时设置 DegreeofParallelism,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26290997/

相关文章:

c# - c# 可执行控制台应用程序的生命周期(如果有)是什么?

.net - 如果我修改基础表,LINQ-to-SQL 会中断吗?

LINQ POI 邻近度

bash - 带有 "export -f <func>"的 BASH 脚本中的 GNU Parallel 在 Crond 时失败并出现 "Command Not Found"错误

parallel-processing - 我如何在 Go 中使用 fmt.Scanf

c# 7za.exe 进程状态

c# - C#中的唯一编号生成

c# - 如何在c# linq中找到集合的最小差异对象

android - 并行执行多个 AsyncTask

c# - 堆栈跟踪中的 +number 是什么意思