Share via


WindowPattern.WaitForInputIdle(Int32) Méthode

Définition

Provoque le blocage du code appelant pendant la durée spécifiée ou jusqu’à ce que le processus associé bascule dans un état d’inactivité (en fonction de l’échéance la plus proche).

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

Paramètres

milliseconds
Int32

Délai, en millisecondes, à attendre que le processus associé devienne inactif. La valeur maximale est Int32.MaxValue.

Retours

true si la fenêtre est passée à l’état inactif ; false si le délai d’attente a été atteint.

Exceptions

Le paramètre passé n’est pas un nombre valide.

Exemples

Dans l’exemple suivant, un WindowPattern modèle de contrôle est obtenu à partir d’un AutomationElement et utilise WaitForInputIdle pour confirmer que l’élément est prêt pour l’interaction utilisateur dans un laps de temps raisonnable.

///--------------------------------------------------------------------
/// <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

Remarques

Cette méthode est généralement utilisée conjointement avec la gestion d’un WindowOpenedEvent.

L’implémentation dépend de l’infrastructure d’application sous-jacente ; Par conséquent, cette méthode peut revenir un certain temps après que la fenêtre est prête pour l’entrée utilisateur. Le code appelant ne doit pas s’appuyer sur cette méthode pour déterminer exactement quand la fenêtre est devenue inactive.

S’applique à