IInvokeProvider.Invoke メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コントロールをアクティブ化し、その単一の明確なアクションを開始する要求を送信します。
public:
void Invoke();
public void Invoke();
abstract member Invoke : unit -> unit
Public Sub Invoke ()
例外
コントロールが有効になっていない場合。
例
次の例では、コントロールの MouseDown イベント ハンドラーに Invoke メソッドを実装します。
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 要求を処理する前に発生させる必要があります。
アクションが完了するまで待機することはできません。または実用的ではありません。
アクションにはユーザーの操作が必要です。
このアクションには時間がかかり、呼び出し元のクライアントが長時間ブロックされます。