文件锁定问题 [英] File lock problem

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

问题描述

偶尔我尝试保存文件时:


-----------------------

xmlDoc.Save(Application.StartupPath + @" \Config.xml");

------------------ -----


我得到这个错误,说该文件无法被访问,因为它的

被另一个进程锁定了(我无法得到它)现在就去做 - 因为

我希望它崩溃...)

有没有办法检查文件是否被另一个进程锁定了

试图保存它?如果它被锁定有没有办法终止其他

进程或某些人将其释放以便可以保存它?


谢谢,
格兰特

解决方案

我无法解答您的具体问题,但如果我尝试打开文件,我会使用

try / catch并且通常在短时间内循环该过程,其中有一些

thread.sleep(0)被抛入。


我无法回答您的具体问题,但如果我尝试打开文件,我会使用

try / catch并且通常会在短时间内循环使用一些

thread.sleep(0)抛入。





不,AFAIK没有办法知道是否一个文件被预先锁定,你有打开它的
并且它会给你错误,使用try / catch块。


这是可能的知道什么进程正在使用给定文件,来自

sysinternals.com的filemon就可以了。怎么样 ?坦率地说,我不知道,IIRC没有一个简单的方法来获取这些信息。当然没有一种管理方式。

欢呼,

-

Ignacio Machin,
ignacio.machin AT dot.state.fl.us

佛罗里达州交通局


格兰特 < GP ***** @ hotmail.com>在消息中写道

news:uF ************** @ TK2MSFTNGP14.phx.gbl ...

偶尔我尝试和保存文件:

-----------------------
xmlDoc.Save(Application.StartupPath + @" \Config.xml");
-----------------------

我收到此错误说文件无法被访问,因为它被另一个进程或其他东西锁定(我现在无法让它实现 -
因为我希望它崩溃......)
有没有办法检查文件是否被另一个进程锁定,试图保存它?如果它被锁定有没有办法终止其他
进程或某些人将其释放以便可以保存它?

谢谢,
Grant



Occasionally when I try and save a document:

-----------------------
xmlDoc.Save(Application.StartupPath + @"\Config.xml");
-----------------------

I get this error saying that the file could not be accessed because its
locked by another process or something (I cant get it to do it now - because
I want it to crash...)
Is there a way to check whether a file is locked by another process befre
trying to save it? If it is locked is there a way to terminate the other
process or somewhow free it up so that it can be saved?

Thanks,
Grant

解决方案

I can''t answer your specific question but if I try to open a file I use
try/catch and usually loop the process over a short time period with some
thread.sleep(0) thrown in.


I can''t answer your specific question but if I try to open a file I use
try/catch and usually loop the process over a short time period with some
thread.sleep(0) thrown in.


Hi,

No, AFAIK there is no way to know if a file is locked beforehand, you have
to open it and it will give you error, use a try/catch block .

It''s possible to know what process is using a given file, filemon from
sysinternals.com does it. how ? frankly I have no idea , IIRC there is no a
easy way to get this info. of course there is not a managed way of doing it.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Grant" <gp*****@hotmail.com> wrote in message
news:uF**************@TK2MSFTNGP14.phx.gbl...

Occasionally when I try and save a document:

-----------------------
xmlDoc.Save(Application.StartupPath + @"\Config.xml");
-----------------------

I get this error saying that the file could not be accessed because its
locked by another process or something (I cant get it to do it now -
because I want it to crash...)
Is there a way to check whether a file is locked by another process befre
trying to save it? If it is locked is there a way to terminate the other
process or somewhow free it up so that it can be saved?

Thanks,
Grant



这篇关于文件锁定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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