Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Count increment inside Parallel For loop

$
0
0

Hi,

I have code like below for Parallel for loop:

int count = 0;
                                                  
Parallel.For(0, dsCsv.Tables[0].Rows.Count, rowCount => {
  count = 0;
  if (ds.Tables[0].Rows[rowCount]["Test"].ToString() != String.Empty) {
             // Do nothing.
             //continue;
   }else {
          Parallel.For(0, dtFromDB.Rows.Count, nextRowCount => {
            
         if(count == 0){
          
          }
   });
});


I am facing issue with count. When inside  loop iterates around 300 plus record and outside loop iterates around 10 somehow count is getting changed because of that getting wrong result. Can you please help me is there any alternative for this to approach same count logic inside parallel loop.

Thanks....


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>