IInvokeProvider.Invoke 方法

定义

发送一个请求来激活控件并启动其单个明确作。

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

注释

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

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

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

  • 无法或不实际等待操作完成。

  • 该操作需要用户交互。

  • 该操作非常耗时,将导致调用客户端长时间阻止。

适用于

另请参阅