WindowPattern.WaitForInputIdle(Int32) Méthode

Définition

Provoque le blocage du code appelant pour l’heure spécifiée ou jusqu’à ce que le processus associé entre dans un état inactif, le cas où il se termine en premier.

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

Durée, en millisecondes, d’attente de l’inactivité du processus associé. La valeur maximale est Int32.MaxValue.

Retours

true si la fenêtre a entré l’état inactif ; false si le délai d’expiration s’est produit.

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 modèle de contrôle et utilise WaitForInputIdle pour confirmer que l’élément est prêt pour l’interaction utilisateur dans un délai 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 retourner un certain temps une fois 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 à