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

Tom picture Tom · Jun 17, 2011 · Viewed 128.1k times · Source

I need to make sure that a process is running before moving on with a method.

The statement is:

Process.Start("popup.exe");

Can you do a WAIT command or set a delay on this value?

Answer

jason picture jason · Jun 17, 2011

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