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 ()
void Invoke ()
function Invoke ()
Not applicable.

Exception typeCondition

ElementNotEnabledException

If the control is not enabled.

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

NoteNote:

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft