TransactionScope如何工作? [英] How does TransactionScope work?

查看:112
本文介绍了TransactionScope如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Method1()实例化一个 TransactionScope 并调用 Method2 c $ c>也实例化一个 TransactionScope ,.NET怎么知道两者在同一范围?
我相信它在内部不使用静态方法,否则它不能很好地在多线程应用程序如ASP.NET上工作。

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.

是否可以创建我的

推荐答案

希望这有助于:

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


对于不熟悉TransactionScope的用户,对Microsoft®.NET Framework 2.0新增的System.Transactions命名空间的一部分。 System.Transactions提供了一个完全集成到.NET Framework中的事务框架,包括但不限于ADO.NET。 Transaction和TransactionScope类是这个命名空间中最重要的两个类。正如问题所暗示的,您可以创建一个TransactionScope实例,并且在该TransactionScope范围内执行的ADO.NET操作将被自动注册(您还可以通过Transaction.Current静态属性访问当前事务):

For those unfamiliar with TransactionScope, it is part of the System.Transactions namespace new to the Microsoft® .NET Framework 2.0. System.Transactions provides a transactions framework fully integrated into the .NET Framework, including but not limited to ADO.NET. The Transaction and TransactionScope classes are two of the most important classes in this namespace. As the question alludes to, you can create a TransactionScope instance, and ADO.NET operations executed within the scope of that TransactionScope will be enlisted automatically (you can also access the current Transaction through the Transaction.Current static property):

using(TransactionScope scope = new TransactionScope())
{
    ... // all operations here part of a transaction
    scope.Complete();
}


这篇关于TransactionScope如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆