TransactionScope 如何运作?
当 Method1()
实例化 TransactionScope
并调用同时实例化 TransactionScope
的 Method2()
时,.NET 如何执行知道两者都在同一范围内吗? 我相信它在内部不使用静态方法,否则它无法在 ASP.NET 等多线程应用程序上正常工作。
是否可以创建我自己的类似 TransactionScope 的类,或者原始类是否使用了 Microsoft 知道其工作原理的特殊功能?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
希望这有帮助:
http://msdn.microsoft.com/en-us/magazine /cc300805.aspx
Hope this helps:
http://msdn.microsoft.com/en-us/magazine/cc300805.aspx
TransactionScope
几乎建立在 COM 之上 - 特别是在 MSDTC 之上。这可以协调事务,并允许嵌套事务。
简而言之,当您第一次调用
TransactionScope
时,事务会向 MSDTC 注册,就像对TransactionScope
的所有其他调用一样。 MSDTC 对它们进行协调。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 toTransactionScope
. MSDTC coordinates them all.答案是,执行可由 TransactionScope 保护、提交和回滚的操作的类必须进行专门编码,以了解“环境”事务。 (这不是魔法。)这个答案很好地解释了这一点:How to enlist with a TransactionScope?< /a>
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?