Vb.net check if the process is running

I started the process:

Dim getUdpate as Process getUpdate = New Process getUpdate.StartInfo.FileName = "C:\UTIL\GETBTCH.BAT" getUpdate.StartInfo.WindowStyle = ProcessWindowStyle.Hidden getUpdate.StartInfo.UseShellExecute = False getUpdate.StartInfo.WorkingDirectory = "C:\UTIL\" getUpdate.Start() getUpdate.Close() 

Then I want to start another process, but first I want to check if the getUpdate process is getUpdate .

How to check if the process is complete?

I already tried to look at the process identifier, but it only displays cmd.exe, and there is a lot of cmd.exe as the process identifier, so I can’t just go and stop it all.

+4
source share
3 answers

You can check the HasExited property of this process. It will return true if the process has completed, and false if it is still running.

You will need to verify this before you call Close() on your getUpdate Process object. Therefore, getProcess must remain open until the procsses process completes.

+5
source

Try:

getUpdate.WaitForExit(); instead

getUpdate.Close()

+2
source

If you are creating a WinForms application or similar interactive interface, I suggest connecting the function to the Exited object instead of polling the HasExited .

(Perhaps you already know this, but) if you use WaitForExit or poll HasExited , your user interface hangs precisely because your code is really waiting for the process to complete.

Your user interface has only one thread and cannot "multitask." This is why these β€œprocessing” actions must be performed in another thread (or, as in this case, another process) and report this to the user interface when they end.

Example:

 ' Handle Exited event and display process information. Private Sub myProcess_Exited(ByVal sender As Object, ByVal e As System.EventArgs) 'Do something in your UI End Sub 

and in your start code:

 getUpdate.EnableRaisingEvents = True AddHandler getUpdate.Exited, AddressOf myProcess_Exited 
0
source

Source: https://habr.com/ru/post/1496476/


All Articles