File is used by another process. How to know which process?

一曲冷凌霜 提交于 2019-11-27 18:13:35

问题


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.


回答1:


You can use ProcessExplorer to search for the file:

  • http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

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.




回答2:


You can use a tool like ProcessMon to see what process is locking a file.




回答3:


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



来源:https://stackoverflow.com/questions/3386157/file-is-used-by-another-process-how-to-know-which-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!