我希望并行运行的TxJobs能够从这个父事务创建一个范围.我该如何工作?
using (var tx = TransactionScope()) { Parallel.Invoke(TxJob1,TxJob2) ; tx.Complete(); }
我传入了一个DependentClone:
using (var tx = new TransactionScope()) { var dtx1 = Transaction.Current.DependentClone( DependentCloneOption.RollbackIfNotComplete) ; var dtx2 = Transaction.Current.DependentClone( DependentCloneOption.RollbackIfNotComplete) ; Parallel.Invoke(() => TxJob1(dtx1),() => TxJob2(dtx2)) ; tx.Complete(); }
在TxJob1和TxJob2方法中,如果我只是在DependentClones上调用Complete,它就可以工作.但是,如果我从克隆创建一个范围,我会得到一个TransactionAbortedException:
void TxJob1(Transaction dt) { using (var tx = new TransactionScope(dt)) { Console.WriteLine(dtx.Transaction@R_791_404[email protected]); tx.Complete(); } }
在main方法中调用Complete,而不是在TxJobs中引发异常.为什么这会失败?
[编辑]如果我在TxJobs中的DependentTransaction上显式调用Complete,那么它可以工作.如果我没有在TxJobs中的新TransactionScope上调用Complete(触发回滚),则父事务失败.看起来我必须在两个Transaction对象上调用Complete.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。