EventWatcherOptions Class
Specifies options for management event watching.
For a list of all members of this type, see EventWatcherOptions Members.
System.Object
System.Management.ManagementOptions
System.Management.EventWatcherOptions
[Visual Basic] Public Class EventWatcherOptions Inherits ManagementOptions [C#] public class EventWatcherOptions : ManagementOptions [C++] public __gc class EventWatcherOptions : public ManagementOptions [JScript] public class EventWatcherOptions extends ManagementOptions
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.
Example
[C#] using System; using System.Management; // This example demonstrates how to specify a timeout and a batch count // when listening to an event using ManagementEventWatcher object. class Sample_EventWatcherOptions { public static int Main(string[] args) { ManagementClass newClass = new ManagementClass(); newClass["__CLASS"] = "TestDeletionClass"; newClass.Put(); EventWatcherOptions options = new EventWatcherOptions(null, new TimeSpan(0,0,0,5), 1); ManagementEventWatcher watcher = new ManagementEventWatcher(null, new WqlEventQuery("__classdeletionevent"), options); MyHandler handler = new MyHandler(); watcher.EventArrived += new EventArrivedEventHandler(handler.Arrived); watcher.Start(); // Delete class to trigger event newClass.Delete(); //For the purpose of this example, we will wait // two seconds before main thread terminates. System.Threading.Thread.Sleep(2000); watcher.Stop(); return 0; } public class MyHandler { public void Arrived(object sender, EventArrivedEventArgs e) { Console.WriteLine("Class Deleted= " + ((ManagementBaseObject)e.NewEvent["TargetClass"])["__CLASS"]); } } } [Visual Basic] Imports System Imports System.Management ' This example demonstrates how to specify a timeout and a batch count ' when listening to an event using the ManagementEventWatcher object. Class Sample_EventWatcherOptions Public Shared Sub Main() Dim newClass As New ManagementClass() newClass("__CLASS") = "TestDeletionClass" newClass.Put() Dim options As _ New EventWatcherOptions(Nothing, New TimeSpan(0, 0, 0, 5), 1) Dim watcher As New ManagementEventWatcher( _ Nothing, _ New WqlEventQuery("__classdeletionevent"), _ options) Dim handler As New MyHandler() AddHandler watcher.EventArrived, AddressOf handler.Arrived watcher.Start() ' Delete class to trigger event newClass.Delete() ' For the purpose of this example, we will wait ' two seconds before main thread terminates. System.Threading.Thread.Sleep(2000) watcher.Stop() End Sub Public Class MyHandler Public Sub Arrived(sender As Object, e As EventArrivedEventArgs) Console.WriteLine("Class Deleted = " & _ CType(e.NewEvent("TargetClass"), ManagementBaseObject)("__CLASS")) End Sub End Class End Class
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Management
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Management (in System.Management.dll)