在 C# 中使用文件的 TransactionScope [英] TransactionScope With Files In C#
问题描述
我一直在使用 TransactionScope 来处理数据库,感觉很好.我正在寻找的是以下内容:
I've been using TransactionScope to work with the database and it feels nice. What I'm looking for is the following:
using(var scope=new TransactionScope())
{
// Do something with a few files...
scope.Complete();
}
但显然这不起作用——如果有 20 个文件,并且第 9 个文件发生异常,则所有前 8 个保持已更改,其余 未更改-- 不执行回滚.那么,为文件实现类似作用域的行为的最佳方法是什么?
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?
我希望有一个简单的答案,但如果没有,您能给我一些提示,或者给我指点相关文章吗?
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?
推荐答案
您正在寻找 事务性 NTFS,由 Windows Vista 引入.
You're looking for Transactional NTFS, introduced by Windows Vista.
这篇关于在 C# 中使用文件的 TransactionScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!