0
我想請教一下DependentTransaction方面,下面的代碼從MSDN了,https://msdn.microsoft.com/en-us/library/system.transactions.dependenttransaction是什麼概念背後產生的TransactionScope的實例,它使用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();
}
,爲什麼我們需要再次創建TransactionScope的實例它在哪裏使用DependentTransaction?僅僅依靠DependentTransaction並調用DependentTransaction.Complete()是不夠的?