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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With