Export (0) Print
Expand All

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()


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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft