5
私はWindows Automationを使用して自分のUIをテストしています。私は、有効なWindowHandleを持っているが、Process.WaitForInputIdle()は十分に長く待たない。私は回避策がありますが、なぜWaitForInputIdle()が機能しないのか分かりません。以下はProcess.WaitForInputIdle()が機能しないのはなぜですか?
小さなコードスニップです:彼のコメントにChaser324で述べたように
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);
尋ねられた質問[こちら](http://stackoverflow.com/questions/3247125/wait-for-wpf-app-to-load-after-starting-with-process-start)に似ているようです。ある時点でProcess.Refresh()を呼び出す必要があるかもしれません。 – Chaser324