DMac the Destroyer DMac the Destroyer - 1 year ago 202
ASP.NET (C#) Question

Parallel.ForEach Set MaxDegreeOfParallelism globally

Say I have a situation where I really want to use

instead of a regular
loop because it's much more performant (and way cooler), but having
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 the
parameter so that my application is super tasty fast and not super tasty broken.

Instead of having to remember to include a
parameter with the magic number every time I invoke
(or any other derivative of it), is there any way to specify the degree of parallelism at the
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download