Invoke Method
Collapse the table of content
Expand the table of content

IInvokeProvider.Invoke Method ()


Sends a request to activate a control and initiate its single, unambiguous action.

Namespace:   System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

void Invoke()

Exception Condition

If the control is not enabled.

Invoke is an asynchronous call and must return immediately without blocking.


This behavior is particularly critical for controls that, directly or indirectly, launch a modal dialog when invoked. Any UI Automation client that instigated the event will remain blocked until the modal dialog is closed.

Invoke raises the InvokedEvent event. If possible, the event should be raised after the control has completed its associated action.

InvokedEvent should be raised before servicing the Invoke request in the following scenarios:

  • It is not possible or practical to wait until the action is complete.

  • The action requires user interaction.

  • The action is time-consuming and will cause the calling client to block for a significant length of time.

The following example implements the Invoke method on the MouseDown event handler of a control. Assume that providerControl is a member variable that was initialized when the class was constructed.

/// <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 });

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2016 Microsoft