FileInfo.MoveTo是否对文件具有隐式锁定? [英] Is FileInfo.MoveTo has implicit lock on file?

查看:171
本文介绍了FileInfo.MoveTo是否对文件具有隐式锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有人可以帮我找到这个问题的答案吗?

FileInfo.MoveTo是否对文件具有隐式锁定?

当我们使用File.move或FileInfo.MoveTo或类似的操作时,实际上会发生什么.

在此先感谢

R.Manjunathan

Hi,

Can someone please help me in finding the answer to this question

Is FileInfo.MoveTo has implicit lock on file?

What actually happen when we use File.move or FileInfo.MoveTo or similar operations.

Thanks in advance

R.Manjunathan

推荐答案

我不确定这些操作是否锁定文件.

但是,我确实看到很多帖子都抱怨他们这样做.这些声明几乎总是错误的,并且是另一个文件操作锁定了文件,并且当代码到达Move()方法时,将调用异常.

因此,如果您解释这仅仅是出于好奇还是由于您尝试执行某项操作而导致的失败,那么这可能会有所帮助.

如果是后者,则发布一小段代码演示该问题将有助于我们为您提供帮助.
I do not know for certain if these operations lock a file or not.

I do however see a lot of posts complaining that they do. Almost always these claims are wrong and it is another file operation that is locking the file and an exception gets called when the code reaches the Move() method.

Therefore, it might help if you explain whether this is just curiosity on your part or as a result of something that you are trying to do, that has failed.

If the latter, posting a small snippet of code that demonstrates the problem would help us to assist you.


如果您真的想知道会发生什么,请尝试此操作.

1)下载进程监视器 [
3)确保您正在捕获事件&运行有问题的程序.观察代码点击移动"时会发生什么
If you really want to know what happens, try this.

1) Download Process Monitor[^] from Microsoft

2) Create a filter so it''s only capturing events from the program in question

NB: You can create include\exclude filters over ''Actions'', so you don''t see too much info,

3) Make sure you''re capturing events & run the program in question. Watch what happens when the code hits ''Move''


这篇关于FileInfo.MoveTo是否对文件具有隐式锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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