开发者

Counter++ in Parallel.ForEach

开发者 https://www.devze.com 2023-01-11 02:53 出处:网络
I understand using an iterator++ inside Parallel.ForEach is not a good option but right now i\'m forced to use a counter inside a Par开发者_开发百科allel.ForEach loop, counter is used to pick up colum

I understand using an iterator++ inside Parallel.ForEach is not a good option but right now i'm forced to use a counter inside a Par开发者_开发百科allel.ForEach loop, counter is used to pick up column names of a dynamic object at runtime.Any suggestion what would be the best option?.I read somewhere at StackOverflow that using "Interlocked" is again a bad design inside Parallel.ForEach.


If you really need parallel processing, the indices will have to be pre-computed. Something like Enumerable.Range(0, cols.Length).ToArray(). Otherwise, each column will depend on the previous one, which obviously doesn't parallelize.

0

精彩评论

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