Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am porting some code to Parallel.ForEach and got an 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;
});
like image 414
John Egbert Avatar asked Sep 21 '10 22:09

John Egbert


2 Answers

return;

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

like image 194
dave Avatar answered Nov 14 '22 17:11

dave


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.

like image 27
Taran Avatar answered Nov 14 '22 17:11

Taran