如何调试这个错误? "该进程无法访问文件X,因为它正由另一个进程使用" [英] How do I debug this error? "The process cannot access the file X because it is being used by another process"

查看:167
本文介绍了如何调试这个错误? "该进程无法访问文件X,因为它正由另一个进程使用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是文件系统的API(在.NET或本地的),试图打开一个文件。我收到以下错误信息:

I am using a file system API (in .NET or a native one) to try to open a file. I receive the following error message:

的过程不能访问文件X,因为它正由另一个进程。

The process cannot access the file X because it is being used by another process.

这是什么错误的意思,我该如何调试呢?

What does this error mean and how can I debug it?

推荐答案

这是什么错误意味着:

此错误意味着你试图打开一个已经打开冲突的访问和共享设置的文件。

This error means that you are trying to open a file that is already opened with conflicting access and sharing settings.

该消息是误导,因为该文件并不一定是由不同的进程打开。这是一个Win32级的异常。这只是意味着还有另外的处理的打开该文件。

The message is misleading because the file is not necessarily opened by a different process. This is a Win32-level exception. It just means that there is another handle opened for that file.

此错误也适用于目录。

如何进行调试:

找出进程或组件在应用程序中打开该文件,也没有将其关闭。您可以使用Sysinternals的进程资源管理器的查找处理功能来查找问题的进程,并关闭句柄。

Find out what process or component in your application opened the file and did not yet close it. You can use Sysinternals Process Explorer's "Find Handle" feature to find the offending process and close the handle.

如果你自己的code打开手柄,没有一般程序,以发现问题。检查您的code。评论code,直到错误消失。

If your own code opened the handle there is no general procedure to find the problem. Review your code. Comment code until the error goes away.

常见的错误是:

  • 渗出的FileStream File.open方法(路径); //泄漏!
  • 未包装的资源使用语句。在大多数情况下,可支配的资源,我们应该放在使用
  • 具有文件打开某些应用程序,如:
    • 在一个文本编辑器
    • 系统开发工具
    • 在数据库服务器
    • 在Windows资源管理器窗口与各自的文件中选择
    • 在命令提示符窗口,具有设置为当前目录下的相应目录
    • Leaking a FileStream: File.Open(path); //leak!
    • Not wrapping resources in a using statement. In most cases disposable resources should we wrapped in using.
    • Having the file open in some app, like:
      • A text editor
      • A development tool
      • A database server
      • A Windows Explorer Window with the respective file selected
      • A Command Prompt Window that has the respective directory set as the current directory

      如何解决:

      使用该文件关闭其他应用程序。请确保您关闭的文件句柄当你与他们做。使用使用语句。

      Close other applications using that file. Make sure that you close your file handles when you are done with them. Use the using statement.

      这篇关于如何调试这个错误? "该进程无法访问文件X,因为它正由另一个进程使用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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