.NET下的原子文件副本 [英] Atomic file copy under .NET

查看:152
本文介绍了.NET下的原子文件副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用System.IO.File.Copy(...)的功能是将文件复制服务器应用程序。我的文件可以是相当大的,因此,它有一个公平的机会,如果机器崩溃,它在复制过程中发生的。

I am building a server app that copies files using System.IO.File.Copy(...) function. My files can be rather large, therefore, it has a fair chance that if the machine crashes, it happens during copying.

重新启动服务后,我应该能够拿起副本任务,并继续。我怎样才能检测一个副本已成功完成或服务器崩溃中断?

After restarting the service, I should be able to pick up the copy tasks and continue. How can I detect if a copy has been successfully completed or interrupted by server crash?

我目前的计划是将文件复制到一个临时的名字,一旦复制完成其重命名为最终的名称。这样,文件命名能够​​结转崩溃的状态信息。

My current plan is to copy the files to a temporary name and once copying completed rename it to the final name. This way the file naming is able to carry the state information over the crash.

你有什么好的/更好的建议?

Do you have any good/better suggestions?

编辑:目标操作系统是Win2003的,因此事务的NTFS不可用

Target OS is Win2003, therefore transactional NTFS is not available

推荐答案

其他建议交易NTFS这是好的,如果你部署在Vista或更高版本。如果您需要支持XP(或更早),那么临时文件之后移动(重命名)是最好的解决方案。

Other have suggested transactional NTFS which is fine if you're deploying on Vista or later. If you need to support XP (or earlier) then temporary file followed by a move (rename) is the best solution.

这个问题的答案类似的问题提供了更多的信息: <一href="http://stackoverflow.com/questions/774098/atomicity-of-file-move">http://stackoverflow.com/questions/774098/atomicity-of-file-move

The answer to this similar question provides more info: http://stackoverflow.com/questions/774098/atomicity-of-file-move

这篇关于.NET下的原子文件副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆