How does TransactionScope work?

Viewed 15706

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?

3 Answers

The answer is that the classes that perform the actions that can be protected, committed, and rolled back by the TransactionScope have to be specifically coded to be aware of the "ambient" transaction. (It's not magic.) This answer explains it well: How to enlist with a TransactionScope?

Related