c# - Out of Memory Exception in Parallel.ForEach -


i using parallel.foreach job got "out of memory exception".

parallel.foreach(flist, (item) => {     string f1 = item.split('|')[0];     string f2 = item.split('|')[1];     = file.readalltext(f1);     b = file.readalltext(f2);      consume(a, b); }); 

flist's size 351, a , b string, each of them has 20kb size. @ time, system memory blown up.

consume return string list, around 1000 strings in each iteration.

how deal it?

try replacing:

  parallel.foreach(flist, (item) =>     {         string f1 = item.split('|')[0];         string f2 = item.split('|')[1];         = file.readalltext(f1);         b = file.readalltext(f2);          consume(a, b);     }); 

with:

    parallel.foreach(flist,      new paralleloptions { maxdegreeofparallelism = 4 },     (item) =>     {         string f1 = item.split('|')[0];         string f2 = item.split('|')[1];         = file.readalltext(f1);         b = file.readalltext(f2);          consume(a, b);     }); 

this prevent many threads being created. can experiment higher numbers , see if performance improves.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -