Search code examples
c#winformsprocessloaded

How know when a winform is loaded by Process.Start?


I'm in a WindowsForm (c# .net 3.5) and on click of a button launch another external application (also .net 3.5) using Process.Start() and understand when it is available after i have launched it.

    ProcessStartInfo psInfo = new ProcessStartInfo(@"MyApplication.exe");
psInfo.RedirectStandardOutput = true;
psInfo.RedirectStandardError = true;
psInfo.UseShellExecute = false;
psInfo.CreateNoWindow = true;
Process proc = Process.Start(psInfo);

proc... IsFullyLoaded()?

How can i do it?


Solution

  • To wait for the process to create its form, call the WaitForInputIdle method.

    To find out whether it's ready, try this:

    bool isReady = proc.WaitForInputIdle(0);
    

    Or, alternatively,

    bool isReady = (proc.MainWindowHandle != IntPtr.Zero);
    

    You can also use the MainWindowHandle property to send messages to the form using the SendMessage API function