IInvokeProvider.Invoke Método

Definición

Envía una solicitud para activar un control e iniciar su única acción inequívoca.

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

Excepciones

Si el control no está habilitado.

Ejemplos

En el ejemplo siguiente se implementa el Invoke método en el controlador de eventos MouseDown de un control . Supongamos que providerControl es una variable miembro que se inicializó cuando se construyó la clase.

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

Comentarios

Invoke es una llamada asincrónica y debe devolverse inmediatamente sin bloqueo.

Note

Este comportamiento es especialmente crítico para los controles que, directa o indirectamente, inician un cuadro de diálogo modal cuando se invocan. Cualquier cliente de Automatización de la interfaz de usuario que instigó el evento permanecerá bloqueado hasta que se cierre el cuadro de diálogo modal.

Invoke genera el InvokedEvent evento . Si es posible, el evento debe generarse después de que el control haya completado su acción asociada.

InvokedEvent debe generarse antes de atender la Invoke solicitud en los escenarios siguientes:

  • No es posible o práctico esperar hasta que se complete la acción.

  • La acción requiere interacción del usuario.

  • La acción consume mucho tiempo y hará que el cliente que realiza la llamada bloquee durante un período de tiempo significativo.

Se aplica a

Consulte también