TransactionScope与C#中的文件[重复]

时间:2022-07-08 13:32:22

This question already has an answer here:

这个问题在这里已有答案:

I've been using TransactionScope to work with the database and it feels nice. What I'm looking for is the following:

我一直在使用TransactionScope来处理数据库,感觉还不错。我正在寻找的是以下内容:

using(var scope=new TransactionScope())
{               
    // Do something with a few files...
    scope.Complete();
}

but obviously this doesn't work -- if there are 20 files, and an exception occurs on the 9th file, all previous 8 remain changed and the rest unchanged -- no rollback is performed. So, what would be the best way to implement a scope-like behavior for files?

但显然这不起作用 - 如果有20个文件,并且第9个文件发生异常,所有之前的8个仍然保持更改而其余的保持不变 - 不执行回滚。那么,为文件实现类似范围的行为的最佳方法是什么?

I'm hoping there is a simple answer, but if not, could you just give me a few pointers, or point me to an related article?

我希望有一个简单的答案,但如果没有,你能给我一些指示,或者指点我的相关文章吗?

2 个解决方案

#1


6  

You're looking for Transactional NTFS, introduced by Windows Vista.

您正在寻找由Windows Vista引入的Transactional NTFS。

Here is a managed wrapper.

这是一个托管包装器。

#2


3  

You can try the .NET Transactional File Manager library available on Codeplex and NuGet. It supports any file system and is not a wrapper over Transactional NTFS.

您可以尝试Codeplex和NuGet上提供的.NET Transactional File Manager库。它支持任何文件系统,并不是Transactional NTFS的包装器。

From the project description:

从项目描述:

Transactional File Manager is a .NET API that supports including file system operations such as file copy, move, delete, append, etc. in a transaction. It's an implementation of System.Transaction.IEnlistmentNotification (works with System.Transactions.TransactionScope).

事务性文件管理器是一种.NET API,支持在事务中包括文件系统操作,如文件复制,移动,删除,追加等。它是System.Transaction.IEnlistmentNotification的一个实现(与System.Transactions.TransactionScope一起使用)。

#1


6  

You're looking for Transactional NTFS, introduced by Windows Vista.

您正在寻找由Windows Vista引入的Transactional NTFS。

Here is a managed wrapper.

这是一个托管包装器。

#2


3  

You can try the .NET Transactional File Manager library available on Codeplex and NuGet. It supports any file system and is not a wrapper over Transactional NTFS.

您可以尝试Codeplex和NuGet上提供的.NET Transactional File Manager库。它支持任何文件系统,并不是Transactional NTFS的包装器。

From the project description:

从项目描述:

Transactional File Manager is a .NET API that supports including file system operations such as file copy, move, delete, append, etc. in a transaction. It's an implementation of System.Transaction.IEnlistmentNotification (works with System.Transactions.TransactionScope).

事务性文件管理器是一种.NET API,支持在事务中包括文件系统操作,如文件复制,移动,删除,追加等。它是System.Transaction.IEnlistmentNotification的一个实现(与System.Transactions.TransactionScope一起使用)。