.net - How to find out a background worker completed its work which is started inside for loop C# -
i started thread collects around >500 records every 5 minutes.then foreach statement created seperate background worker each details obtained.i collect data checking condition in queue('qu' in db).while backgroundworkers do_work event update 'qu' status 'pr'.
backgroundworker bw1; collection collect = new collection() foreach (transaction trans in transactionlist) { try { collect.transactiondetails = trans; bw1 = new backgroundworker(); bw1.dowork += new doworkeventhandler(bw1_dowork); bw1.runworkercompleted += new runworkercompletedeventhandler(bw1_runworkercompleted); bw1.runworkerasync(collect); } catch { } } this lengthy process must run using backgroundworker. question if process takes more thread sleep time complete same records 'qu' status collected again.how can understand process still running , make thread wait more time till complete
you need somehow keep track of running processes. basic way use counter variable increment on creating backgroundworker , decrement when it's completed. find out number of still running backgroundworkers looking @ variable's value.
if you're on .net 4, might want have @ task parallel library.
another thing: far understand create worker thread on 500 items? seems lot me. consider partitioning workload fewer larger pieces.
Comments
Post a Comment