15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

616 ❘ ChaPTer 23 system.trAnsActiOns<br />

Creation Time: 7:56:24 PM<br />

Status: Active<br />

Local ID: 0d2f5ada-32aa-40eb-b9d7-cc6aa9a2a554:1<br />

Distributed ID: 501abd91-e512-47f3-95d5-f0488743293d<br />

Abort the Transaction (y/n)<br />

Transaction promotion requires the DTC to be started. If promoting transactions fails with your system,<br />

verify that the DTC service is started. Starting the Component Services MMC snap-in, you can see the<br />

actual status of all DTC transactions running on your system.<br />

By selecting Transaction List on the tree view, you can see all active transactions. In Figure 23-3, you can<br />

see that there is a transaction active with the same distributed identifier as was shown with the console<br />

output earlier. If you verify the output on your system, make sure that the transaction has a timeout <strong>and</strong><br />

aborts in case the timeout is reached. After the timeout, you cannot see the transaction in the transaction<br />

list anymore. You can also verify the transaction statistics with the same tool. Transaction Statistics shows<br />

the number of committed <strong>and</strong> aborted transactions.<br />

figure 23-3<br />

dependent Transactions<br />

With dependent transactions, you can influence one transaction from multiple threads. A dependent<br />

transaction depends on another transaction <strong>and</strong> influences the outcome of the transaction.<br />

The sample application DependentTransactions creates a dependent transaction for a new thread.<br />

The method TxThread() is the method of the new thread where a DependentTransaction object is<br />

passed as a parameter. Information about the dependent transaction is shown with the helper method<br />

DisplayTransactionInformation(). Before the thread exits, the Complete() method of the dependent<br />

transaction is invoked to define the outcome of the transaction. A dependent transaction can define the<br />

outcome of the transaction by calling either the Complete() or Rollback() method. The Complete()<br />

method sets the success bit. If the root transaction finishes, <strong>and</strong> if all dependent transactions have set the<br />

success bit to true, the transaction commits. If any of the dependent transactions set the abort bit by<br />

invoking the Rollback() method, the complete transaction aborts:<br />

static void TxThread(object obj)<br />

{<br />

DependentTransaction tx = obj as DependentTransaction;<br />

Utilities.DisplayTransactionInformation("Dependent Transaction",<br />

tx.TransactionInformation);<br />

Thread.Sleep(3000);<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!