c# - App stops at foreach number 3286090 -


basically have problem application stops after loop 3286090 or batch 1735.

i have list of 1894 of validated addresses @ point in application , makes possible combinations , calculates distance , travel time per batch. sub function calls local web service takes 60 180 seconds complete each batch , writes result .csv file. (writing excel file existing excel libraries convulates memory excessively wasn't option.)

there no exception. there no system log. , every single "break on exception" option ctrl+alt+e enabled.

if (startnumber <= batchnumber) {     calculaterouteinfo(waypointdescarraylist, batchnumber, address); } 

code seems fail here. moment batchnumber reaches 1735 , compares startnumber (which in case have tried entering 1734 redo last batch / 1735 current batch , try skip @ 1736 or higher.)

no matter number above 1736 application reaches end @ specific number of comparing x batchnumber 1735 when tell application compare higher number 1800. ends there.

i tried fiddling around conditions , checking memory leaks not case. web service functions on other batches before number. manually making batch , sending web-service functions well.

here full code.

private static void preprocesscalculation(xlocate.addressresponse[] foundaddressess) {     int batchnumber = 1;     list<xroute.waypointdesc[]> waypointdescarraylist = new list<xroute.waypointdesc[]>();     foreach (var foundaddress in foundaddressess)     {// 1. foundaddresses containts 1894 foundaddress'          foreach (var address in foundaddress.wrappedresultlist)         {// 2. each foundaddress.wrappedresultlist containts (in case) 1x address.             gc.collect();             gc.waitforpendingfinalizers();             gc.collect();             var watch = stopwatch.startnew();             foreach (var foundaddressdest in foundaddressess)             {// 3. here combine each address every address , each address make batch of combinations calculate.                 foreach (var addressdest in foundaddressdest.wrappedresultlist)                 { // 4.                     #region add waypointdesc                     var waypointdesclist = new list<xroute.waypointdesc>();                     waypointdesclist.add(new xroute.waypointdesc()                     {                         linktype = xroute.linktype.auto_linking,                         wrappedcoords = new xroute.point[] {                              new xroute.point() {                                  point = new xroute.plainpoint() {                                     x = address.coordinates.point.x,                                      y = address.coordinates.point.y                                  }                             }                         }                     });                     waypointdesclist.add(new xroute.waypointdesc()                     {                         linktype = xroute.linktype.auto_linking,                         wrappedcoords = new xroute.point[] {                              new xroute.point() {                                  point = new xroute.plainpoint() {                                     x = addressdest.coordinates.point.x,                                      y = addressdest.coordinates.point.y                                  }                             }                         }                     });                     waypointdescarraylist.add(waypointdesclist.toarray());                     #endregion                 }             }             if (startnumber <= batchnumber)             {  // calculates data , not fail.                 calculaterouteinfo(waypointdescarraylist, batchnumber, address);             }             waypointdescarraylist.clear();             watch.stop();             elapsedtime += watch.elapsed.totalseconds;             console.clear();             console.writeline("voortgang calculatie... {0}/{1} ({2}s (+{3}s))", batchnumber, totalbatches, elapsedtime, watch.elapsed.totalseconds);             batchnumber++;         }     } } // 5. when going through 1735th iteration skips end of function.  private static void calculaterouteinfo(list<xroute.waypointdesc[]> finallist, int batchnumber, xlocate.resultaddress address) {     string startlocation = string.format("{0}-{1}-{2}-{3}", address.country, address.postcode, address.city, address.street);     var matrixdistance = matrixtemplate.copy();     matrixdistance.rows.add(startlocation);     var matrixtime = matrixtemplate.copy();     matrixtime.rows.add(startlocation);      var bulkrouteinfo = xrouteclient.calculatebulkrouteinfo(finallist.toarray(), null, null, null);     finallist.clear();      var column = 1;     foreach (var routeinfo in bulkrouteinfo.wrappedbulkrouteinforesult)     {         matrixdistance.rows[0][column] = routeinfo.routeinfo.distance;         matrixtime.rows[0][column] = routeinfo.routeinfo.time;         column++;     }     writeoutputmatrix(filename, batchnumber, matrixdistance, matrixtime); }  private static void writeoutputmatrix(string filename, int batchnumber, datatable matrixdistance, datatable matrixtime) {     string newpath = string.format("c:/result/{0}/", filename);     if (!directory.exists(newpath))     {         var newdirectory = directory.createdirectory(newpath);         console.writeline("result mappen aangemaakt.");     }      var matrixdistancebytes = encoding.getencoding("iso-8859-1").getbytes(matrixdistance.tocsv());     using (stream s = file.create(string.format("{0}{1}-distance_{2}.csv", newpath, filename, batchnumber), matrixdistancebytes.length))     {         s.write(matrixdistancebytes, 0, matrixdistancebytes.length);         console.writeline(string.format("result {0}{1}-distance_{2}.csv aangemaakt!", newpath, filename, batchnumber));     }      var matrixtimebytes = encoding.getencoding("iso-8859-1").getbytes(matrixtime.tocsv());     using (stream s = file.create(string.format("{0}{1}-time_{2}.csv", newpath, filename, batchnumber), matrixtimebytes.length))     {         s.write(matrixtimebytes, 0, matrixtimebytes.length);         console.writeline(string.format("result {0}{1}-time_{2}.csv aangemaakt!", newpath, filename, batchnumber));     } } 

edit: workaround.

    private static void preprocesscalculation(xlocate.addressresponse[] foundaddressess)     {         int batchnumber = 1;         list<xroute.waypointdesc[]> waypointdescarraylist = new list<xroute.waypointdesc[]>();         foreach (var foundaddress in foundaddressess)         {             if (startnumber < batchnumber)             {                 foreach (var address in foundaddress.wrappedresultlist)                 {                      gc.collect();                     gc.waitforpendingfinalizers();                     gc.collect();                     var watch = stopwatch.startnew();                     foreach (var foundaddressdest in foundaddressess)                     {                         foreach (var addressdest in foundaddressdest.wrappedresultlist)                         {                             #region add waypointdesc                             var waypointdesclist = new list<xroute.waypointdesc>();                             waypointdesclist.add(new xroute.waypointdesc()                             {                                 linktype = xroute.linktype.auto_linking,                                 wrappedcoords = new xroute.point[] {                                  new xroute.point() {                                      point = new xroute.plainpoint() {                                         x = address.coordinates.point.x,                                          y = address.coordinates.point.y                                      }                                 }                             }                             });                             waypointdesclist.add(new xroute.waypointdesc()                             {                                 linktype = xroute.linktype.auto_linking,                                 wrappedcoords = new xroute.point[] {                                  new xroute.point() {                                      point = new xroute.plainpoint() {                                         x = addressdest.coordinates.point.x,                                          y = addressdest.coordinates.point.y                                      }                                 }                             }                             });                             waypointdescarraylist.add(waypointdesclist.toarray());                             #endregion                         }                     }                      calculaterouteinfo(waypointdescarraylist, batchnumber, address);                      waypointdescarraylist.clear();                     watch.stop();                     elapsedtime += watch.elapsed.totalseconds;                     console.clear();                     console.writeline("voortgang calculatie... {0}/{1} ({2}s (+{3}s))", batchnumber, totalbatches, elapsedtime, watch.elapsed.totalseconds);                     batchnumber++;                 }             }             else             {                 batchnumber++;//debug             }         }     } 

i moved condition 1 stack higher , seems solve problem far. still solve issue why stops mid-foreach. foundaddress.wrappedresultlist can contain more 1 result (in stress test not.).

to temporarily solve issue have optimized code prevent excessive , needless foreach-loops.

then keep count until number crash occurs , start new loop continuing left off.

a dirty workaround works while not yet know of solution.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -