开发者

Is there an equivalent to 'continue' in a Parallel.ForEach?

开发者 https://www.devze.com 2023-01-16 21:55 出处:网络
I am porting some code to Parallel.ForEach and got a开发者_开发百科n error with a continue I have in the code. Is there something equivalent I can use in a Parallel.ForEach functionally equivalent to

I am porting some code to Parallel.ForEach and got a开发者_开发百科n error with a continue I have in the code. Is there something equivalent I can use in a Parallel.ForEach functionally equivalent to continue in a foreach loop?

Parallel.ForEach(items, parallelOptions, item =>
{
    if (!isTrue)
        continue;
});


return;

(the body is just a function called for each item)


When you converted your loop into a compatible definition for the Parallel.Foreach logic, you ended up making the statement body a lambda. Well, that is an action that gets called by the Parallel function.

So, replace continue with return, and break with Stop() or Break() statements.

0

精彩评论

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