Share via


IInvokeProvider.Invoke 方法

定义

发送请求以激活控件并启动其单一、明确的操作。

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 是一个异步调用且必须立即返回而不阻塞。

注意

此行为对于被调用时直接或间接启动模式对话框的控件而言尤其重要。 引发该事件的任何 UI 自动化客户端将保持被阻止的状态,直到模式对话框关闭为止。

Invoke 引发 InvokedEvent 事件。 如果可能,应在控件完成其关联操作后引发 事件。

InvokedEvent 在以下情况下, Invoke 应在为请求提供服务之前引发:

  • 不可能等至操作完成,或这一做法不实际。

  • 该操作需要用户交互。

  • 该操作非常耗时,会导致调用客户端在很长一段时间内被阻止。

适用于

另请参阅