I've an application which does
Process.Start()
to start another application 'ABC'. I want to wait till that application ends (process dies) and continue my execution. How can I do it?
There may be multiple instances of the application 'ABC' running at the same time.
I think you just want this:
See the MSDN page for the method. It also has an overload where you can specify the timeout, so you're not potentially waiting forever.
Try this:
Process.WaitForExit should be just what you're looking for I think.
You could use wait for exit or you can catch the HasExited property and update your UI to keep the user "informed" (expectation management):
Use
Process.WaitForExit
? Or subscribe to theProcess.Exited
event if you don't want to block? If that doesn't do what you want, please give us more information about your requirements.I had a case where
Process.HasExited
didn't change after closing the window belonging to the process. SoProcess.WaitForExit()
also didn't work. I had to monitorProcess.Responding
that went to false after closing the window like that:Perhaps this helps someone.