c# - Using TransactionScope with Parallel.Foreach Loop -


i trying use transaction parallel.foreach

code snippet :

list<int> ilist = new list<int>(); // having int random numbers  /// check final collection count  concurrentqueue<int> q= new concurrentqueue<in>();  using(var scope = new transactionscope()) {      transaction roottr = transaction.current;      parallel.foreach(ilist, item =>     {          dependenttransaction dt = roottr.dependentclone(dependentcloneoption.rollbackifnotcomplete);          if(item == 7)              throw new argumentexception("7 occurred"); // throwing exception          q.enqueue(item);          thread.sleep(5000);          dt.complete();     });      ts.complete(); } 

but getting exception see value in queue(q).

i want rollback parallel processing item queue(q) empty in case of failure.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -