Share via


IInvokeProvider.Invoke メソッド

定義

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

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

例外

コントロールが有効でない場合。

次の例では、コントロールの Invoke MouseDown イベント ハンドラーに メソッドを実装します。 providerControlが、 クラスの構築時に初期化されたメンバー変数であるとします。

/// <summary>
/// Responds to an InvokePattern.Invoke by simulating a MouseDown event.
/// </summary>
/// <remarks>
/// ProviderControl is a button control object that also implements 
/// IRawElementProviderSimple.
/// </remarks>
void IInvokeProvider.Invoke()
{
    // If the control is not enabled, we're responsible for letting UIAutomation know.
    // It catches the exception and then throws it to the client.
    if (false == (bool)rawElementProvider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id))
    {
        throw new ElementNotEnabledException();
    }

    // Create arguments for the event. The parameters aren't used.
    MouseEventArgs mouseArgs = new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0);

    // Invoke the MouseDown handler. We cannot call MyControl_MouseDown directly, 
    // because it is illegal to update the UI from a different thread.
    MouseEventHandler onMouseEvent = ProviderControl.RootButtonControl_MouseDown;
    ProviderControl.BeginInvoke(onMouseEvent, new object[] { this, mouseArgs });
    }
}

注釈

Invoke は非同期呼び出しであるため、クライアントをブロックせずに即座に戻る必要があります。

Note

呼び出されたときにモーダル ダイアログを直接的または間接的に表示するコントロールでは、この動作は特に重要です。 イベントを発生させたすべての UI オートメーション クライアントは、モーダル ダイアログが閉じられるまで、ブロックされたままになります。

Invoke は、InvokedEvent イベントを発生させます。 可能であれば、コントロールが関連付けられたアクションを完了した後にイベントを発生させる必要があります。

InvokedEvent は、次のシナリオで要求を処理する Invoke 前に発生する必要があります。

  • 処理が完了するまで待機することが不可能または非現実的である。

  • 処理にユーザー操作が必要になる。

  • アクションは時間がかかり、呼び出し元のクライアントが長時間ブロックされます。

適用対象

こちらもご覧ください