Condividi tramite


WindowPattern.WaitForInputIdle(Int32) Metodo

Definizione

Comporta il blocco del codice chiamante per il lasso di tempo specificato o finché il processo associato non entra in stato di inattività, in base alla prima condizione che viene soddisfatta.

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

Parametri

milliseconds
Int32

Quantità di tempo, espressa in millisecondi, per cui aspettare che il processo associato diventi inattivo. Il massimo è Int32.MaxValue.

Restituisce

true se la finestra è diventata inattiva. false se si è verificato il timeout.

Eccezioni

Il parametro passato non è un numero valido.

Esempio

Nell'esempio seguente viene ottenuto un WindowPattern modello di controllo da un AutomationElement oggetto e viene WaitForInputIdle usato per verificare che l'elemento sia pronto per l'interazione dell'utente entro un periodo di tempo ragionevole.

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

Commenti

Questo metodo viene in genere usato insieme alla gestione di un WindowOpenedEventoggetto .

L'implementazione dipende dal framework dell'applicazione sottostante; pertanto questo metodo può restituire un certo tempo dopo che la finestra è pronta per l'input dell'utente. Il codice chiamante non deve basarsi su questo metodo per verificare esattamente quando la finestra è diventata inattiva.

Si applica a