嗨,首先感谢您对这个问题的关注;有什么办法可以在c#
中实现这样的事务using (Transactionscope x=new Transactionscope ())
{
Thead A()=> Independent Transactionscope() A(Insert into table X )
Thead B()=> Independent Transactionscope() B(Insert into table Y )
Thead C()=> Independent Transactionscope() C(Insert into table Z )
Thread.WaitAll(A,B,C)
commit big transaction x/ rollback big transaction x
}
为了使用TransactionScope
跨越多个线程,您需要使用DependentClone将线程绑定到父级TransactionScope
。
步骤是:
TransactionScope
DependentClone
创建一个DependentTransaction
,然后将此DependentTransaction
实例传递给新线程。TransactionScope(DependentTransaction)
构造函数重载来创建链接的TransactionScope
,子线程可以在其中执行本地事务。TransactionScope
和DependentTransaction
TransactionScope
DependentTransaction
将立即需要使用MSDTC。SqlBulkCopy
),您需要测量是否并行插入到不同的表中,同一数据库下的相同数据库中。 DTC交易可保证锁定开销或返回任何性能收益。async
,则需要TransactionScopeAsyncFlowOption.Enabled