views:

59

answers:

2

When Method1() instantiates a TransactionScope and calls Method2() that also instantiates a TransactionScope, how does .Net know both are in the same scope? I believe it doesn't use static methods internally otherwise it wouldn't work well on multithreaded applications like asp.net.

Is it possible to create my own TransactionScope-like class or does the original one use special features those just Microsoft knows how they work?

+1  A: 

TransactionScope pretty much builds on top of COM - specifically over MSDTC.

This coordinates transactions, and allows nesting of transactions.

In short, when you first call TransactionScope, a transaction registers with MSDTC, as would all other calls to TransactionScope. MSDTC coordinates them all.

Oded
Sometimes transactions (specially database ones) are promoted to DTC but not always.
Eduardo
@Eduardo - that's true. The LTM (Lightweight Transaction Manager may promote a transaction to distributed via MSDTC).
Oded
+1  A: 

Hope this helps:

http://msdn.microsoft.com/en-us/magazine/cc300805.aspx

Jordão
Sure!!!They may use Thread.SetData() also:http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1
Eduardo