VB.Net 3.5 Check if file is in use

后端 未结 5 1681
甜味超标
甜味超标 2021-01-15 03:43

I have an update program that is completely independent of my main application. I run the update.exe to update the app.exe. To check to see if the file is in use, I move it

5条回答
  •  自闭症患者
    2021-01-15 04:16

    You could do the following to check if the application has other instances running:

    Process.GetProcessesByName("app.exe", "Machine1").Length > 0
    

    Which is a more appropriate way of checking if the app is running.

    Have a look at File.Move MSDN documentation. It details what exceptions are thrown. You are allowed to rename an exe even if it is in Use in Vista.

提交回复
热议问题