Редагувати

Поділитися через


IInvokeProvider.Invoke Method

Definition

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

public:
 void Invoke();
public void Invoke ();
abstract member Invoke : unit -> unit
Public Sub Invoke ()

Exceptions

If the control is not enabled.

Examples

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

Remarks

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

Note

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.

Applies to

See also