File.Move的原子 [英] Atomicity of File.Move

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

问题描述

我要重命名的目录中的文件作为一个原子事务。该文件将不会被更改目录。路径是作为一个UNC路径到一个NTFS文件系统,可能是任一服务器03或08上。

I want to rename a file in a directory as an atomic transaction. The file will not be changing directories. The path is provided as a UNC Path to an NTFS file system, probably on either Server 03 or 08.

时File.Move()的原子为这些目的?如,它要么成功完成或失败,使得原来的文件仍然完好?

Is File.Move() atomic for these purposes? As in, it either completes successfully or fails such that the original file is still intact?

我的直觉说,是的,但我想确认一下。

My gut says yes, but I wanted to make sure.

推荐答案

是的,在NTFS。从<一个href="http://social.microsoft.com/Forums/en-US/netfxbcl/thread/38733d72-e1d4-493b-8533-cbdef22f46ed#reply">here:

Yes, in NTFS. From here:

顺便说一句,如果你是NTFS下运行,那么文件操作都是原子在文件系统级别。会出现一个重命名在一个操作就任何更高的code而言。您所看到的问题几乎似乎是其中的FileInfo对象被在应用程序之间共享的问题。它是一个MarshalByRef对象,因此可以在远程环境中使用。不知道这是否适用于你。

As an aside if you are running under NTFS then file operations are atomic at the file system level. A rename will occur in a single operation as far as any higher code is concerned. The problem you are seeing almost appears to be an issue where the FileInfo object is being shared across applications. It is a MarshalByRef object and therefore can be used in remoting environments. Don't know if this applies to you.

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

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