15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

624 ❘ ChaPTer 23 system.trAnsActiOns<br />

}<br />

Transaction.Current.TransactionInformation);<br />

scope.Complete();<br />

}<br />

}<br />

catch (TransactionAbortedException ex)<br />

{<br />

Console.WriteLine("ThreadMethod — Transaction was aborted, {0}",<br />

ex.Message);<br />

}<br />

finally<br />

{<br />

if (dTx != null)<br />

{<br />

dTx.Complete();<br />

}<br />

}<br />

}<br />

static void TransactionCompleted(object sender, TransactionEventArgs e)<br />

{<br />

Utilities.DisplayTransactionInformation("TX completed",<br />

e.Transaction.TransactionInformation);<br />

}<br />

Running the application now, you can see that the main thread <strong>and</strong> the newly created thread are using, <strong>and</strong><br />

influencing, the same transaction. The transaction listed by the threads has the same identifier. If with one<br />

thread the success bit is not set by calling the Complete() method, the complete transaction aborts:<br />

Main thread TX<br />

Creation Time: 23:00:57<br />

Status: Active<br />

Local ID: 2fb1b54d-61f5-4d4e-a55e-f4a9e04778be:1<br />

Distributed ID: 00000000-0000-0000-0000-000000000000<br />

Thread TX<br />

Creation Time: 23:00:57<br />

Status: Active<br />

Local ID: 2fb1b54d-61f5-4d4e-a55e-f4a9e04778be:1<br />

Distributed ID: 00000000-0000-0000-0000-000000000000<br />

TX completed<br />

Creation Time: 23:00:57<br />

Status: Committed<br />

Local ID: 2fb1b54d-61f5-4d4e-a55e-f4a9e04778be:1<br />

Distributed ID: 00000000-0000-0000-0000-000000000000<br />

TX completed<br />

Creation Time: 23:00:57<br />

Status: Committed<br />

Local ID: 2fb1b54d-61f5-4d4e-a55e-f4a9e04778be:1<br />

Distributed ID: 00000000-0000-0000-0000-000000000000<br />

isolaTion leVel<br />

At the beginning of this chapter, you see the ACID properties used to describe transactions. The<br />

letter I (Isolation) in ACID is not always fully required. For performance reasons, you might reduce<br />

isolation requirements, but you must be aware of the issues that you will encounter if you change<br />

the isolation level.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!