InvokePattern.Invoke 方法

定義

傳送要求以啟動控制項,並啟始其單一明確的動作。

C#
public void Invoke();

例外狀況

此項目不支援 InvokePattern 控制項模式,或是處於隱藏或封鎖狀態。

項目未啟用。 當使用者介面自動化提供者對 IsEnabled 屬性已實作自己的處理方式時會引發。

範例

在下列範例中, InvokePattern 會從控件取得控制項模式,並 Invoke 呼叫 方法。

C#
///--------------------------------------------------------------------
/// <summary>
/// Obtains an InvokePattern control pattern from a control
/// and calls the InvokePattern.Invoke() method on the control.
/// </summary>
/// <param name="targetControl">
/// The control of interest.
/// </param>
///--------------------------------------------------------------------
private void InvokeControl(AutomationElement targetControl)
{
    InvokePattern invokePattern = null;

    try
    {
        invokePattern =
            targetControl.GetCurrentPattern(InvokePattern.Pattern)
            as InvokePattern;
    }
    catch (ElementNotEnabledException)
    {
        // Object is not enabled
        return;
    }
    catch (InvalidOperationException)
    {
        // object doesn't support the InvokePattern control pattern
        return;
    }

    invokePattern.Invoke();
}

備註

Invoke的呼叫應該會立即傳回,而不會封鎖。 不過,此行為完全相依於 Microsoft UI 自動化提供者實作。 在呼叫 Invoke 會導致封鎖問題 (例如強制回應對話框) 個別協助程式線程的情況下,可能需要呼叫 方法。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱