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
source share