AutomationEvent Class
This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Represents an Automation event.
Inheritance Hierarchy
System..::.Object
System.Runtime.InteropServices.Automation..::.AutomationEvent
Namespace: System.Runtime.InteropServices.Automation
Assembly: System.Windows (in System.Windows.dll)
Syntax
Public NotInheritable Class AutomationEvent
public sealed class AutomationEvent
The AutomationEvent type exposes the following members.
Methods
Name | Description | |
---|---|---|
AddEventHandler | Attaches the specified delegate to the Automation event. | |
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
RemoveEventHandler | Detaches the specified delegate from the Automation event. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Events
Name | Description | |
---|---|---|
EventRaised | Occurs when the Automation event occurs. |
Top
Examples
The following code example demonstrates how to handle Automation events.
Private Sub SearchEmail()
UpdateStatusMessage("Searching Inbox for 'WindowsPhone'...")
' The following code demonstrates three ways to handle Automation
' events. In Visual Basic, all three ways use the AutomationEvent class.
searchEvent =
AutomationFactory.GetEvent(outlook, "AdvancedSearchComplete")
' The first way is demonstrated by the Handles clause of the
' SearchEvent_EventRaised method, which requires the WithEvents modifier
' on the searchEvent variable declaration.
' The second way uses the AddHandler syntax with the EventRaised event,
' and does not require the WithEvents modifier.
' AddHandler searchEvent.EventRaised, AddressOf SearchEvent_EventRaised
' The third way uses the AutomationEvent.AddEventHandler method, and
' requires the use of a delegate with an API signature that matches the
' Automation event.
' searchEvent.AddEventHandler(
' New AdvancedSearchCompleteDelegate(AddressOf SearchComplete))
' Begin the search.
outlook.AdvancedSearch("Inbox",
"urn:schemas:mailheader:subject ci_phrasematch 'WindowsPhone'",
True, "SubjectSearch")
End Sub
Private WithEvents searchEvent As AutomationEvent
Sub SearchEvent_EventRaised(ByVal sender As Object,
ByVal e As AutomationEventArgs) Handles searchEvent.EventRaised
SearchComplete(e.Arguments(0))
End Sub
' Required only with the second two ways of handling Automation events.
' Private Delegate Sub AdvancedSearchCompleteDelegate(ByRef search As Object)
' Note: Visual Basic does not support the use of custom delegates for
' events with optional parameters.
Private Sub SearchComplete(ByRef search As Object)
Dim searchResults As New List(Of String)
For Each result As Object In search.Results
searchResults.Add(result.Subject)
Next
SetResultsList(searchResults)
End Sub
private void SearchEmail()
{
UpdateStatusMessage("Searching Inbox for 'WindowsPhone'...");
// The following code demonstrates three ways to handle Automation
// events. The first two ways use the AutomationEvent class.
// The last two ways require the use of a delegate with
// an API signature that matches the Automation event.
AutomationEvent searchEvent = AutomationFactory
.GetEvent(outlook, "AdvancedSearchComplete");
// The first way:
searchEvent.EventRaised += (sender, e) =>
{
SearchComplete(e.Arguments[0]);
};
// The second way:
// searchEvent.AddEventHandler(
// new AdvancedSearchCompleteDelegate(SearchComplete));
// The third way:
// outlook.AdvancedSearchComplete +=
// new AdvancedSearchCompleteDelegate(SearchComplete);
// Begin the search.
outlook.AdvancedSearch("Inbox",
"urn:schemas:mailheader:subject ci_phrasematch 'WindowsPhone'",
true, "SubjectSearch");
}
// Required only with the second two ways of handling Automation events.
private delegate void AdvancedSearchCompleteDelegate(dynamic search);
// To use custom delegates for events with optional parameters, you
// must specify default values in the delegate signature as shown here:
// private delegate void MyEventHandlerDelegate(int i, float f=77);
private void SearchComplete(dynamic search)
{
List<String> searchResults = new List<String>();
foreach (dynamic result in search.Results)
{
searchResults.Add(result.Subject);
}
SetResultsList(searchResults);
}
Version Information
Windows Phone OS
Supported in: 8.1, 8.0, 7.1
Platforms
Windows Phone
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
System.Runtime.InteropServices.Automation Namespace