c# - How I implement Multithread pool for a repetitive process -


i need test() calculations, want put cpu core @ work find solution faster.

for (int i= 0; i<1000000; i++)  {     result[i] = test(i);     if (result[i] == 0)      {         break;     } } 

i have work backgroundworker before. , create array of n bgworker , handle queue myself looks trouble.

so found task.factory, seem similar want, still don't know how handle each separate task wait result , stop when found asnwer.

task<string> task = task.factory.startnew<string>                     (() => downloadstring("http://www.google.com/")); string result = task.result; 

or maybe there other solution problem.

parallel.for(0, 1000000, (i, loopstate) => {     result[i] = test(i);     if (result[i] == 0)      {         loopstate.stop();         return;     } }); 

how to: write simple parallel.for loop

how to: stop or break parallel.for loop


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -