InvokePattern.Invoke メソッド

定義

コントロールをアクティブ化し、その単一の明確なアクションを開始する要求を送信します。

public:
 void Invoke();
public void Invoke();
member this.Invoke : unit -> unit
Public Sub Invoke ()

例外

要素は、 InvokePattern コントロール パターンをサポートしていないか、非表示またはブロックされています。

要素が有効になっていません。 UI オートメーション プロバイダーが IsEnabled プロパティの独自の処理を実装している場合に発生する可能性があります。

次の例では、 InvokePattern コントロール パターンがコントロールから取得され、 Invoke メソッドが呼び出されます。

///--------------------------------------------------------------------
/// <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();
}
'''--------------------------------------------------------------------
''' <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 Sub InvokeControl(ByVal targetControl As AutomationElement) 
    Dim invokePattern As InvokePattern = Nothing
    
    Try
        invokePattern = _
        DirectCast(targetControl.GetCurrentPattern(invokePattern.Pattern), _
        InvokePattern)
    Catch e As ElementNotEnabledException
        ' Object is not enabled.
        Return
    Catch e As InvalidOperationException
        ' Object doesn't support the InvokePattern control pattern
        Return
    End Try
    
    invokePattern.Invoke()

End Sub

注釈

Invokeの呼び出しは、ブロックせずに直ちに返されます。 ただし、この動作は、Microsoft UI オートメーション プロバイダーの実装に完全に依存します。 Invokeを呼び出すとブロックの問題 (モーダル ダイアログなど) が発生するシナリオでは、メソッドを呼び出すために別のヘルパー スレッドが必要になる場合があります。

適用対象

こちらもご覧ください

  • UI オートメーション