Warum nicht Prozess.WaitForInputIdle() arbeiten?

Ich bin mit Windows-Automatisierung zu testen, mein UI und bin öffnen und schließen von Prozessen. Ich will eine gültige WindowHandle, aber der Prozess.WaitForInputIdle() wartet nicht lange genug. Ich habe eine Arbeit um Sie herum, aber verstehe nicht, warum WaitForInputIdle() nicht funktioniert.

Unten ist ein kleiner code-Ausschnitt:

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);
  • Scheint ähnlich wie die Frage here. Möglicherweise müssen Sie anrufen Prozess.Refresh () - irgendwann.
InformationsquelleAutor Curtis | 2012-07-18
Schreibe einen Kommentar