問題描述
我對 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模板網!