【发布时间】:2017-07-04 03:58:44
【问题描述】:
想问一下DependentTransaction方面的问题,以下代码来自MSDN,https://msdn.microsoft.com/en-us/library/system.transactions.dependenttransaction
private static void WorkerThread(object transaction)
{
//Create a DependentTransaction from the object passed to the WorkerThread
DependentTransaction dTx = (DependentTransaction)transaction;
//Sleep for 1 second to force the worker thread to delay
Thread.Sleep(1000);
//Pass the DependentTransaction to the scope, so that work done in the scope becomes part of the transaction passed to the worker thread
using (TransactionScope ts = new TransactionScope(dTx))
{
//Perform transactional work here.
//Call complete on the transaction scope
ts.Complete();
}
//Call complete on the dependent transaction
dTx.Complete();
}
为什么我们需要在使用 DependentTransaction 的地方再次创建 TransactionScope 的实例?仅仅依赖 DependentTransaction 并调用 DependentTransaction.Complete() 还不够吗?
【问题讨论】:
标签: c# entity-framework dbcontext transactionscope