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 -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -