IInvokeProvider.Invoke 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發送啟動控制並啟動單一且明確行動的請求。
public:
void Invoke();
public void Invoke();
abstract member Invoke : unit -> unit
Public Sub Invoke ()
例外狀況
如果控制未被啟用。
範例
以下範例實 Invoke 作了控制項的 MouseDown 事件處理程序。 假設 是 providerControl 建構類別時初始化的成員變數。
/// <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 });
}
}
備註
Invoke 是異步呼叫,而且必須立即傳回而不封鎖。
Note
對於直接或間接叫用時啟動強制回應對話框的控件而言,此行為特別重要。 煽動事件的任何UI自動化用戶端都會保持封鎖狀態,直到模式對話框關閉為止。
Invoke提升事件。InvokedEvent 若可能,應在控制組完成相關動作後再提出事件。
InvokedEvent 在以下情況下,應在服務 Invoke 請求前提出:
無法或不切實際地等到動作完成為止。
動作需要用戶互動。
此動作耗時,且會導致呼叫用戶端長時間阻塞。