Share via


WindowPattern.WaitForInputIdle(Int32) メソッド

定義

呼び出し元のコードは、指定された時間、または関連付けられたプロセスがアイドル状態に入るまでブロックされます。どちらが最初に完了するかは関係ありません。

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

パラメーター

milliseconds
Int32

関連付けられたプロセスがアイドル状態になるまで待機する時間。単位はミリ秒です。 最大値は Int32.MaxValue です

戻り値

ウィンドウがアイドル状態になっている場合は true、タイムアウトが発生した場合は false

例外

渡されたパラメーターは有効な数ではありません。

次の例では、 WindowPattern から AutomationElement コントロール パターンを取得し、 を使用 WaitForInputIdle して、妥当な時間内に要素がユーザー操作の準備ができているかどうかを確認します。

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

注釈

このメソッドは、通常、 の処理 WindowOpenedEventと組み合わせて使用されます。

実装は、基になるアプリケーション フレームワークに依存します。したがって、このメソッドは、ウィンドウがユーザー入力の準備ができたらしばらくしてからを返す場合があります。 呼び出し元のコードは、ウィンドウがアイドル状態になった正確なタイミングを確認するために、このメソッドに依存しないようにする必要があります。

適用対象