Why is the Process.WaitForInputIdle () process not working?

I use Windows Automation to test my interface and open and close processes. I want to have a valid WindowHandle, but Process.WaitForInputIdle () does not wait long enough. I have a job, but don't understand why WaitForInputIdle () is not working.

Below is a small snapshot of the code:

Process = new Process
              {
                 StartInfo =
                 {
                     WorkingDirectory = directory,
                     FileName = EXECUTABLE_FILE_NAME
                 }
              };

Process.Start();

//Process.WaitForInputIdle() doesn't work, 
//so will use a while loop until MainWindowHandle isn't IntPtr.Zero anymore,
//or until 10 seconds have elapsed

int count = 0;

while (Process.MainWindowHandle == IntPtr.Zero && count<100)
{
    count++;
    Thread.Sleep(100);
}

AppElement = AutomationElement.FromHandle(Process.MainWindowHandle);
+5
source share
1 answer

As Chaser324 stated in a comment, the answer to my question can be found here .

I basically need to add a call to Process.Refresh () inside the "while" loop.

+2
source

All Articles