How to make PLINQ to spawn more concurrent threads in .NET 4.0 beta 2?

纵然是瞬间 提交于 2019-12-10 16:02:55

问题


In former versions of Parallel Extensions you could set the number of threads:

enumerable.AsParallel(numberOfThreads)

But now that overload is not available anymore. How to do it now?


回答1:


In the new version you can specify it with the extension method ".WithDegreeOfParallelism(int degreeOfParallelism)".

IE:

enumerable.AsParallel().WithDegreeOfParallelism(numberOfThreads)



回答2:


I really have no idea why it changed, so I can't answer the question, but it seems like if the developer specifies the number of threads, then the parallel runtime won't be able to perform the operation in the most optimal way based on the currently available hardware threads.

I don't want to specify number of threads. The beauty of PLINQ is that it just goes parallel without me having to figure out any threading logic.



来源:https://stackoverflow.com/questions/1777140/how-to-make-plinq-to-spawn-more-concurrent-threads-in-net-4-0-beta-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!