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

例外狀況

傳入的參數不是有效的數字。

範例

在下列範例中,會從 AutomationElement 取得控制項模式, WindowPattern 並使用 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 處理搭配使用。

實作相依于基礎應用程式架構;因此,這個方法可能會在視窗準備好進行使用者輸入之後傳回一些時間。 呼叫程式碼不應該依賴這個方法來確定視窗何時變成閒置狀態。

適用於