C# - Making a Process.Start wait until the process has start-up C# - Making a Process.Start wait until the process has start-up windows windows

C# - Making a Process.Start wait until the process has start-up


Do you mean wait until it's done? Then use Process.WaitForExit:

var process = new Process {    StartInfo = new ProcessStartInfo {        FileName = "popup.exe"    }};process.Start();process.WaitForExit();

Alternatively, if it's an application with a UI that you are waiting to enter into a message loop, you can say:

process.Start();process.WaitForInputIdle();

Lastly, if neither of these apply, just Thread.Sleep for some reasonable amount of time:

process.Start();Thread.Sleep(1000); // sleep for one second


I also needed this once, and I did a check on the window title of the process. If it is the one you expect, you can be sure the application is running. The application I was checking needed some time for startup and this method worked fine for me.

var process = Process.Start("popup.exe");while(process.MainWindowTitle != "Title"){    Thread.Sleep(10);}


The answer of 'ChrisG' is correct, but we need to refresh MainWindowTitle every time and it's better to check for empty.... like this:

var proc = Process.Start("popup.exe");while (string.IsNullOrEmpty(proc.MainWindowTitle)){    System.Threading.Thread.Sleep(100);    proc.Refresh();}