可能重复:
Is there a way to check if a file is in use?
Check if a file is open我怎么知道文件已经打开或正在使用?
我怎么能知道文件已打开或使用。
public bool FileIsLocked(string strFullFileName)
{
bool blnReturn = false;
System.IO.FileStream fs;
try
{
fs = System.IO.File.Open(strFullFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None);
fs.Close();
}
catch (System.IO.IOException ex)
{
blnReturn = true;
}
return blnReturn;
}
我觉得上面的代码不能正常工作
http://stackoverflow.com/questions/1304/how-继承to-check-for-file-lock-in-c – vulkanino 2012-02-14 13:14:55
请注意,您使用的功能如th在使用它时,可能会过时。文件可以被锁定,您检查的文件不是,反之亦然。通常最好尝试用你需要的任何文件处理,并在出现错误时作出反应。 – 2012-02-14 13:18:03
我得到这个代码,但它不能正常工作 – bkac 2012-02-14 13:21:07