InvokePattern.Invoke Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sends a request to activate a control and initiate its single, unambiguous action.
public:
void Invoke();
public void Invoke ();
member this.Invoke : unit -> unit
Public Sub Invoke ()
Exceptions
The element does not support the InvokePattern control pattern or is hidden or blocked.
The element is not enabled. Can be raised when a UI Automation provider has implemented its own handling of the IsEnabled property.
Examples
In the following example an InvokePattern control pattern is obtained from a control and the Invoke method is called.
///--------------------------------------------------------------------
/// <summary>
/// Obtains an InvokePattern control pattern from a control
/// and calls the InvokePattern.Invoke() method on the control.
/// </summary>
/// <param name="targetControl">
/// The control of interest.
/// </param>
///--------------------------------------------------------------------
private void InvokeControl(AutomationElement targetControl)
{
InvokePattern invokePattern = null;
try
{
invokePattern =
targetControl.GetCurrentPattern(InvokePattern.Pattern)
as InvokePattern;
}
catch (ElementNotEnabledException)
{
// Object is not enabled
return;
}
catch (InvalidOperationException)
{
// object doesn't support the InvokePattern control pattern
return;
}
invokePattern.Invoke();
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains an InvokePattern control pattern from a control
''' and calls the InvokePattern.Invoke() method on the control.
''' </summary>
''' <param name="targetControl">
''' The control of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub InvokeControl(ByVal targetControl As AutomationElement)
Dim invokePattern As InvokePattern = Nothing
Try
invokePattern = _
DirectCast(targetControl.GetCurrentPattern(invokePattern.Pattern), _
InvokePattern)
Catch e As ElementNotEnabledException
' Object is not enabled.
Return
Catch e As InvalidOperationException
' Object doesn't support the InvokePattern control pattern
Return
End Try
invokePattern.Invoke()
End Sub
Remarks
Calls to Invoke should return immediately without blocking. However, this behavior is entirely dependent on the Microsoft UI Automation provider implementation. In scenarios where calling Invoke causes a blocking issue (such as a modal dialog) a separate helper thread may be required to call the method.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기