c# - Parallel.ForEach Freezing during final iterations -


this first time working parrllel.foreach , having issue. shame because needed performance out of program , getting it.

i in last iterations foreach freezing. not exposing error messages. consolewriteline() comes halt. when pause in debugger scope of parallel.foreach highlighted.

   using (dbdatacontext db = datacontextfactory.getthreadscopeddatacontext<dbdatacontext>())             {                 products = (from r in db.tbl_products                            r.date >= _datecheck                            select r                  ).tolist();                  int rcount = products.count();                  console.writeline("total products: {0}", rcount);                  parallel.foreach(products, new paralleloptions { maxdegreeofparallelism = 8 }, product =>                 {                     dbdatacontext db2 = datacontextfactory.getthreadscopeddatacontext<dbdatacontext>();                       checkinventory(product, db2);                   });                  console.writeline("ended inventory check {0}", datetime.now);             } 

the last phase of checkinventory() method create record of match

  private static void addnewinventorymatch(tbl_product product, tbl_inventory item, int matchtype)         {               dbdatacontext db = datacontextfactory.getthreadscopeddatacontext<dbdatacontext>("4");              tbl_inventorymatch newmatch = new tbl_inventorymatch();           //... add records                db.tbl_inventorymatches.insertonsubmit(newmatch);             //  db.submitchanges();           } 

i have looked on web try , find causing , have had no luck. simple console app run nightly.

also after locks vs cannot compile project unless restart vs. error message.

error   11  not copy "obj\x86\debug\inventory-match.exe" "bin\debug\inventory-match.exe". exceeded retry count of 10. failed.  inventory-match error   12  unable copy file "obj\x86\debug\inventory-match.exe" "bin\debug\inventory-match.exe". process cannot access file 'bin\debug\inventory-match.exe' because being used process. inventory-match 

links: datacontextfactory = http://weblog.west-wind.com/posts/2008/feb/05/linq-to-sql-datacontext-lifetime-management

i had same problem long time ago, try using getdatacontext instead of getthreadscopeddatacontext


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? -