文件被另一个进程使用。如何知道是哪个进程?
我的程序中不断出现该异常。我如何知道哪个进程锁定了它,无论是通过程序代码还是通过对 Windows 执行某些操作?
System.IO.IOException:进程无法访问文件“file.ext”,因为它正在被另一个进程使用。
I keep getting that exception in my program. How do I know which process locked it, either by program code or by doing something with windows?
System.IO.IOException : The process cannot access the file 'file.ext' because it is being used by another process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 ProcessExplorer 搜索该文件:
只需运行它(也许您需要以管理员权限启动它),按
Ctrl-F
并输入要运行的文件的名称被锁定 - 它将找到所有与给定名称匹配的打开句柄,并告诉您它属于哪个进程。You can use ProcessExplorer to search for the file:
Just run that (maybe you need to launch it with administrator rights), hit
Ctrl-F
and type in the name of the file which is locked - it will find all open handles which match the given name, and tell you which process it belongs to.您可以使用
ProcessMon
等工具查看哪个进程正在锁定文件。You can use a tool like
ProcessMon
to see what process is locking a file.看看这个: http://www.emptyloop.com/unlocker/
我用它始终告诉您哪个进程已锁定它,并让您有机会完全解锁它。特别是当您调试图像处理应用程序并且它在没有正确关闭文件的情况下崩溃时非常有用。
希望这有帮助!
肖恩
Have a look at this: http://www.emptyloop.com/unlocker/
I use it all the time, tells you which process has locked it and gives you the chance to unlock it fully. Useful especially for when your debugging image manipulation apps and it bombs out without closing the file properly.
Hope this helps!
Sean
您遇到的错误消息表明您尝试删除的文件当前正在被另一个进程使用。您可以采取以下几个步骤来解决此问题:
您需要确定哪个进程正在使用该文件并停止它。您可以使用内置的 Windows 实用程序资源监视器或 Process Explorer 等第三方工具来执行此操作。
使用资源监视器:
通过在“开始”菜单搜索栏中键入 resmon 并按 Enter 键打开资源监视器。
转到 CPU 选项卡。
使用关联句柄搜索框查找您的文件
识别持有该句柄的进程并结束它。
使用进程资源管理器:
从 Microsoft 网站下载并运行 Process Explorer。
按 Ctrl+F 打开搜索对话框。
搜索该文件。
识别持有该句柄的进程并结束它。
The error message you're encountering indicates that the file you're trying to delete is currently in use by another process. Here are a few steps you can take to resolve this issue:
You need to identify which process is using the file and stop it. You can do this using the built-in Windows utility Resource Monitor or a third-party tool like Process Explorer.
Using Resource Monitor:
Open Resource Monitor by typing resmon in the Start menu search bar and pressing Enter.
Go to the CPU tab.
Use the Associated Handles search box to find your file
Identify the process holding the handle and end it.
Using Process Explorer:
Download and run Process Explorer from the Microsoft website.
Press Ctrl+F to open the search dialog.
Search for the file .
Identify the process holding the handle and end it.