我对 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!