.net - Parallel.ForEach() - 多少个线程?

标签 .net parallel-processing parallel.foreach

我正在下载文件,这意味着即使我只有 2 个内核,创建两个以上的线程也会提高性能。

是否Parallel.ForEach()只制作与内核数量一样多的线程,
即使我将 ParallelOptions.MaxDegreeOfParallelism 设置为更高的值?

最佳答案

从文档:

The MaxDegreeOfParallelism limits the number of concurrent operations run by Parallel method calls that are passed this ParallelOptions instance to the set value, if it is positive. If MaxDegreeOfParallelism is -1, then there is no limit placed on the number of concurrently running operations.



这个函数只抛出 ArgumentOutOfRangeExceptionMaxDegreeOfParalleism 的类型是整数。所以这意味着,它可以创建比内核数更多的线程。

我可以确认,因为我已经运行了很多 xml 生成过程,并且任务管理器显示的进程数与我之前设置的完全相同。

关于.net - Parallel.ForEach() - 多少个线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12933308/

相关文章:

.net - 如何为 .NET 3.5 执行自定义查询接口(interface)?

c - 将二维数组的分布式 block 发送到 MPI 中的根进程

c# - 将 foreach 转换为 Parallel.ForEach

java 8并行流问题

c# - HttpWebResponse.GetResponseStream() (似乎)毫无异常(exception)地失败

.net - 修改后如何重新启动应用程序/重新读取 app.config 文件(.NET)?

c - 如何在 OpenCL 中将元素添加到数组末尾?

c# - 为什么互锁这么慢

.net - 如何取消任何当前的 Parallel.ForEach 并重新开始

c# - Html.AntiForgeryToken() 由于加密异常而失败