C# - System.Transactions.TransactionScope(C# - System.Transactions.TransactionScope)
问题描述
我对 TransactionScope 类很好奇.
I was curious about the TransactionScope class.
在大多数情况下,我认为它是用于数据库连接(这就是我使用它的目的).
For the most part, I assume it was intended for database connections (which is what I've used it for).
我的问题是,您可以将任何代码放在 TransactionScope 的 using 块中以使其具有事务性吗?MS 文档对此并不清楚.
My question, is can you put any code in the using-block of a TransactionScope to make it transactional? MS documentation is not clear on this.
如果它可以用于使数据库连接以外的代码成为事务性的,那么支持哪些?如果它能让 System.IO.File 操作成为事务性的,我觉得这很疯狂.
If it can be used to make code other than database connections transactional, which ones are supported? It would seem crazy to me if it could make System.IO.File operations transactional.
推荐答案
TransactionScope 不仅适用于数据库.每个实现 IEnlistmentNotification 接口的组件都可以参与事务范围的两阶段提交.
TransactionScope is not only for the databases. Every component that implements IEnlistmentNotification interface can participate in two-phase commit of the transaction scope.
以下是事务性内存存储的示例:http://www.codeproject.com/KB/dotnet/Transactional_Repository.aspx
Here is an example of transactional in-memory storage: http://www.codeproject.com/KB/dotnet/Transactional_Repository.aspx
此外,我不确定 .NET 中是否有用于事务文件 IO 的组件,但实现此类组件非常容易 - 最新的操作系统(如 Vista 和 Windows Server 2008)支持事务文件 IO.
Also, I'm not sure if there are components in .NET for transactional file IO, but it is pretty easy to implement such component - latest OS like Vista and Windows Server 2008 have support for transaction file IO.
这篇关于C# - System.Transactions.TransactionScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# - System.Transactions.TransactionScope


基础教程推荐
- 创建属性设置器委托 2022-01-01
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01