EventArrivedEventArgs Class
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.
Holds event data for the EventArrived event.
public ref class EventArrivedEventArgs : System::Management::ManagementEventArgs
public class EventArrivedEventArgs : System.Management.ManagementEventArgs
type EventArrivedEventArgs = class
inherit ManagementEventArgs
Public Class EventArrivedEventArgs
Inherits ManagementEventArgs
- Inheritance
The following asynchronous example sets up a WMI timer to raise an event every second, and removes it when no longer needed. The ManagementEventWatcher defines several .NET Framework events which are raised when WMI events are delivered. Delegates are attached to these events for handling the incoming data.
using System;
using System.Management;
// This example shows asynchronous consumption of events.
// In this example you are listening for timer events.
// The first part of the example sets up the timer.
public class EventWatcherAsync
{
public EventWatcherAsync()
{
// Set up a timer to raise events every 1 second
//=============================================
ManagementClass timerClass =
new ManagementClass("__IntervalTimerInstruction");
ManagementObject timer = timerClass.CreateInstance();
timer["TimerId"] = "Timer1";
timer["IntervalBetweenEvents"] = 1000;
timer.Put();
// Set up the event consumer
//==========================
// Create event query to receive timer events
WqlEventQuery query =
new WqlEventQuery("__TimerEvent",
"TimerId=\"Timer1\"");
// Initialize an event watcher and
// subscribe to timer events
ManagementEventWatcher watcher =
new ManagementEventWatcher(query);
// Set up a listener for events
watcher.EventArrived +=
new EventArrivedEventHandler(
this.HandleEvent);
// Start listening
watcher.Start();
// Do something in the meantime
System.Threading.Thread.Sleep(10000);
// Stop listening
watcher.Stop();
}
private void HandleEvent(object sender,
EventArrivedEventArgs e)
{
Console.WriteLine("Event arrived !");
}
public static void Main(string[] args)
{
// start the event watcher
EventWatcherAsync eventWatcher = new
EventWatcherAsync();
}
}
Imports System.Management
' This example shows asynchronous consumption of events.
' In this example you are listening for timer events.
' The first part of the example sets up the timer.
Public Class EventWatcherAsync
Public Sub New()
' Set up a timer to raise events every 1 second
'=============================================
Dim timerClass As New ManagementClass( _
"__IntervalTimerInstruction")
Dim timer As ManagementObject = _
timerClass.CreateInstance()
timer("TimerId") = "Timer1"
timer("IntervalBetweenEvents") = 1000
timer.Put()
' Set up the event consumer
'==========================
' Create event query to receive timer events
Dim query As New WqlEventQuery("__TimerEvent", _
"TimerId=""Timer1""")
' Initialize an event watcher and subscribe to
' events that match this query
Dim watcher As New ManagementEventWatcher(query)
' Set up a listener for events
AddHandler watcher.EventArrived, _
AddressOf Me.HandleEvent
' Start listening
watcher.Start()
' Do something in the meantime
System.Threading.Thread.Sleep(10000)
' Stop listening
watcher.Stop()
End Sub
Private Sub HandleEvent(ByVal sender As Object, _
ByVal e As EventArrivedEventArgs)
Console.WriteLine("Event arrived !")
End Sub
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
'start the event watcher
Dim eventWatcher As New EventWatcherAsync
Return 0
End Function
End Class
Context |
Gets the operation context echoed back from the operation that triggered the event. (Inherited from ManagementEventArgs) |
New |
Gets the WMI event that was delivered. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Өнім | Нұсқалар |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
.NET кері байланысы
.NET — бастапқы коды ашық жоба. Пікір қалдыру үшін сілтемені таңдаңыз: