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
Post a Comment