开发者

Parallel.ForEach Set MaxDegreeOfParallelism globally

Say I have a situation where I really want to use Parallel.ForEach instead of a regular foreach loop because it's much more performant (and way cooler), but having .NET determine the degree of parallelism for me leads to disastrous effects.

Now say that I've discovered the magic number that I need to place in t开发者_StackOverflow社区he ParallelOptions.MaxDegreeOfParallelism parameter so that my application is super tasty fast and not super tasty broken.

Instead of having to remember to include a ParallelOptions parameter with the magic number every time I invoke Parallel.ForEach (or any other derivative of it), is there any way to specify the degree of parallelism at the web.config level? Or some other approach where the value can be set globally and invisibly so I don't have to rely on the memory of myself and fellow developers any time we want to gain the benefits of parallelism?


The short answer is No, you can't configure this parameter using a config file, however you can still have a const variable that all your call can refer to.


You could make your own wrapper function that calls Parallel.Foreach that reads the degree from a config file or from a constant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜