EventWatcherOptions コンストラクタ ()
アセンブリ: System.Management (system.management.dll 内)


イベント クラスが __InstanceCreationEvent であるために、Win32_Process のインスタンスが作成されたときにクライアントが通知を受信するしくみを説明する例を次に示します。詳細については、MSDN ライブラリ (http://msdn.microsoft.com/library/ja) で Windows Management Instrumentation に関するドキュメントを参照してください。クライアントは WaitForNextEvent メソッドを呼び出して、イベントを同期的に受信します。この例は、コード例の実行中にメモ帳などのプロセスを開始することでテストできます。
Imports System Imports System.Management ' This example shows synchronous consumption of events. ' The client is blocked while waiting for events. Public Class EventWatcherPolling Public Overloads Shared Function _ Main(ByVal args() As String) As Integer ' Create event query to be notified within 1 second of ' a change in a service Dim query As String query = "SELECT * FROM" & _ " __InstanceCreationEvent WITHIN 1 " & _ "WHERE TargetInstance isa ""Win32_Process""" ' Event options Dim eventOptions As New EventWatcherOptions eventOptions.Timeout = System.TimeSpan.MaxValue ' Initialize an event watcher and subscribe to events ' that match this query Dim watcher As New ManagementEventWatcher( _ "root\CIMV2", query, eventOptions) ' Block until the next event occurs ' Note: this can be done in a loop ' if waiting for more than one occurrence Console.WriteLine( _ "Open an application (notepad.exe) to trigger an event.") Dim e As ManagementBaseObject = _ watcher.WaitForNextEvent() 'Display information from the event Console.WriteLine( _ "Process {0} has created, path is: {1}", _ CType(e("TargetInstance"), _ ManagementBaseObject)("Name"), _ CType(e("TargetInstance"), _ ManagementBaseObject)("ExecutablePath")) 'Cancel the subscription watcher.Stop() Return 0 End Function 'Main End Class 'EventWatcherPolling
using System; using System.Management; // This example shows synchronous consumption of events. // The client is blocked while waiting for events. public class EventWatcherPolling { public static int Main(string[] args) { // Create event query to be notified within 1 second of // a change in a service string query = "SELECT * FROM" + " __InstanceCreationEvent WITHIN 1 " + "WHERE TargetInstance isa \"Win32_Process\""; // Event options EventWatcherOptions eventOptions = new EventWatcherOptions(); eventOptions.Timeout = System.TimeSpan.MaxValue; // Initialize an event watcher and subscribe to events // that match this query ManagementEventWatcher watcher = new ManagementEventWatcher("root\\CIMV2", query, eventOptions); // Block until the next event occurs // Note: this can be done in a loop if waiting for // more than one occurrence Console.WriteLine( "Open an application (notepad.exe) to trigger an event."); ManagementBaseObject e = watcher.WaitForNextEvent(); //Display information from the event Console.WriteLine( "Process {0} has been created, path is: {1}", ((ManagementBaseObject)e ["TargetInstance"])["Name"], ((ManagementBaseObject)e ["TargetInstance"])["ExecutablePath"]); //Cancel the subscription watcher.Stop(); return 0; } }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


EventWatcherOptions コンストラクタ (ManagementNamedValueCollection, TimeSpan, Int32)
アセンブリ: System.Management (system.management.dll 内)

Public Sub New ( _ context As ManagementNamedValueCollection, _ timeout As TimeSpan, _ blockSize As Integer _ )
Dim context As ManagementNamedValueCollection Dim timeout As TimeSpan Dim blockSize As Integer Dim instance As New EventWatcherOptions(context, timeout, blockSize)
public EventWatcherOptions ( ManagementNamedValueCollection context, TimeSpan timeout, int blockSize )
public: EventWatcherOptions ( ManagementNamedValueCollection^ context, TimeSpan timeout, int blockSize )
public EventWatcherOptions ( ManagementNamedValueCollection context, TimeSpan timeout, int blockSize )
public function EventWatcherOptions ( context : ManagementNamedValueCollection, timeout : TimeSpan, blockSize : int )

イベント クラスが __InstanceCreationEvent であるために、Win32_Process のインスタンスが作成されたときにクライアントが通知を受信するしくみを説明する例を次に示します。詳細については、MSDN ライブラリ (http://msdn.microsoft.com/library/ja) で Windows Management Instrumentation に関するドキュメントを参照してください。クライアントは WaitForNextEvent メソッドを呼び出して、イベントを同期的に受信します。この例は、コード例の実行中にメモ帳などのプロセスを開始することでテストできます。
Imports System Imports System.Management ' This example shows synchronous consumption of events. ' The client is blocked while waiting for events. Public Class EventWatcherPolling Public Overloads Shared Function _ Main(ByVal args() As String) As Integer ' Create event query to be notified within 1 second of ' a change in a service Dim query As String query = "SELECT * FROM" & _ " __InstanceCreationEvent WITHIN 1 " & _ "WHERE TargetInstance isa ""Win32_Process""" ' Event options ' blockSize = 1 to receive one event Dim eventOptions As New EventWatcherOptions( _ Nothing, System.TimeSpan.MaxValue, 1) ' Initialize an event watcher and subscribe to events ' that match this query Dim watcher As New ManagementEventWatcher( _ "root\CIMV2", query, eventOptions) ' Block until the next event occurs ' Note: this can be done in a loop ' if waiting for more than one occurrence Console.WriteLine( _ "Open an application (notepad.exe) to trigger an event.") Dim e As ManagementBaseObject = _ watcher.WaitForNextEvent() 'Display information from the event Console.WriteLine( _ "Process {0} has created, path is: {1}", _ CType(e("TargetInstance"), _ ManagementBaseObject)("Name"), _ CType(e("TargetInstance"), _ ManagementBaseObject)("ExecutablePath")) 'Cancel the subscription watcher.Stop() Return 0 End Function 'Main End Class 'EventWatcherPolling
using System; using System.Management; // This example shows synchronous consumption of events. // The client is blocked while waiting for events. public class EventWatcherPolling { public static int Main(string[] args) { // Create event query to be notified within 1 second of // a change in a service string query = "SELECT * FROM" + " __InstanceCreationEvent WITHIN 1 " + "WHERE TargetInstance isa \"Win32_Process\""; // Event options // blockSize = 1 to receive one event EventWatcherOptions eventOptions = new EventWatcherOptions(null, System.TimeSpan.MaxValue , 1); // Initialize an event watcher and subscribe to events // that match this query ManagementEventWatcher watcher = new ManagementEventWatcher("root\\CIMV2", query, eventOptions); // Block until the next event occurs // Note: this can be done in a loop if waiting for // more than one occurrence Console.WriteLine( "Open an application (notepad.exe) to trigger an event."); ManagementBaseObject e = watcher.WaitForNextEvent(); //Display information from the event Console.WriteLine( "Process {0} has been created, path is: {1}", ((ManagementBaseObject)e ["TargetInstance"])["Name"], ((ManagementBaseObject)e ["TargetInstance"])["ExecutablePath"]); //Cancel the subscription watcher.Stop(); return 0; } }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


EventWatcherOptions コンストラクタ
- EventWatcherOptions コンストラクタ ()のページへのリンク