Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Process.WaitForInputIdle() work?

Tags:

process

wpf

I am using Windows Automation to test my UI and am opening and closing processes. I want to have a valid WindowHandle, but Process.WaitForInputIdle() doesn't wait long enough. I have a work around, but don't understand why WaitForInputIdle() doesn't work.

Below is a small code snip:

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);
like image 563
Curtis Avatar asked Jul 18 '12 18:07

Curtis


1 Answers

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

I basically need to add a call to Process.Refresh() inside of my 'while' loop.

like image 90
Curtis Avatar answered Nov 13 '22 16:11

Curtis