WindowPattern.WaitForInputIdle(Int32) Methode

Definition

Bewirkt, dass der aufrufende Code für die angegebene Zeitspanne oder solange blockiert wird, bis der zugeordnete Prozess in den Leerlauf wechselt, je nachdem, was zuerst zutrifft.

public:
 bool WaitForInputIdle(int milliseconds);
public bool WaitForInputIdle (int milliseconds);
member this.WaitForInputIdle : int -> bool
Public Function WaitForInputIdle (milliseconds As Integer) As Boolean

Parameter

milliseconds
Int32

Die Zeitspanne in Millisekunden, während der gewartet werden soll, dass der zugeordnete Prozess in den Leerlauf wechselt. Das Maximum ist Int32.MaxValue.

Gibt zurück

true, wenn das Fenster in den Leerlauf gewechselt hat, false, wenn das Timeout aufgetreten ist.

Ausnahmen

Der übergebene Parameter ist keine gültige Zahl.

Beispiele

Im folgenden Beispiel wird ein WindowPattern Steuerelementmuster aus AutomationElement einem abgerufen und verwendet WaitForInputIdle , um zu bestätigen, dass das Element innerhalb einer angemessenen Zeitspanne für die Benutzerinteraktion bereit ist.

///--------------------------------------------------------------------
/// <summary>
/// Obtains a WindowPattern control pattern from an automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A WindowPattern object.
/// </returns>
///--------------------------------------------------------------------
private WindowPattern GetWindowPattern(AutomationElement targetControl)
{
    WindowPattern windowPattern = null;

    try
    {
        windowPattern =
            targetControl.GetCurrentPattern(WindowPattern.Pattern)
            as WindowPattern;
    }
    catch (InvalidOperationException)
    {
        // object doesn't support the WindowPattern control pattern
        return null;
    }
    // Make sure the element is usable.
    if (false == windowPattern.WaitForInputIdle(10000))
    {
        // Object not responding in a timely manner
        return null;
    }
    return windowPattern;
}
'''------------------------------------------------------------------------
''' <summary>
''' Obtains a WindowPattern control pattern from an automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A WindowPattern object.
''' </returns>
'''------------------------------------------------------------------------
Private Function GetWindowPattern(ByVal targetControl As AutomationElement) As WindowPattern
    Dim windowPattern As WindowPattern = Nothing

    Try
        windowPattern = DirectCast( _
        targetControl.GetCurrentPattern(windowPattern.Pattern), _
        WindowPattern)
    Catch
        ' object doesn't support the WindowPattern control pattern
        Return Nothing
    End Try
    ' Make sure the element is usable.
    If False = windowPattern.WaitForInputIdle(10000) Then
        ' Object not responding in a timely manner
        Return Nothing
    End If
    Return windowPattern
End Function 'GetWindowPattern

Hinweise

Diese Methode wird in der Regel in Verbindung mit der Behandlung von WindowOpenedEventverwendet.

Die Implementierung hängt vom zugrunde liegenden Anwendungsframework ab. Daher kann diese Methode einige Zeit zurückgeben, nachdem das Fenster für die Benutzereingabe bereit ist. Der aufrufende Code sollte sich nicht auf diese Methode verlassen, um genau zu ermitteln, wann das Fenster im Leerlauf ist.

Gilt für: