EventWatcherOptions クラス

定義

管理イベント ウォッチのオプションを指定します。

public ref class EventWatcherOptions : System::Management::ManagementOptions
public class EventWatcherOptions : System.Management.ManagementOptions
type EventWatcherOptions = class
    inherit ManagementOptions
Public Class EventWatcherOptions
Inherits ManagementOptions
継承
EventWatcherOptions

次の例は、イベント クラスが__InstanceCreationEventされているために、Win32_Processのインスタンスが作成されたときにクライアントが通知を受け取る方法を示しています。 詳細については、 Windows Management Instrumentation のドキュメントを参照してください。 クライアントは WaitForNextEvent メソッドを呼び出して、イベントを同期的に受信します。 この例は、コード例の実行中にメモ帳などのプロセスを開始することでテストできます。

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;
    }
}
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

コンストラクター

EventWatcherOptions()

イベント ウォッチのための EventWatcherOptions クラスの新しいインスタンスを、既定値を使用して初期化します。 これはパラメーターなしのコンストラクターです。

EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32)

指定した値を使用して、EventWatcherOptions クラスの新しいインスタンスを初期化します。

プロパティ

BlockSize

ブロック操作のブロック サイズを取得または設定します。 イベントを待機する場合、この値は制御を戻す前に待機するイベント数を指定します。

Context

WMI (Windows Management Instrumentation) コンテキスト オブジェクトを取得または設定します。 これは、カスタマイズされた操作のためのコンテキスト情報をサポートしている WMI プロバイダーに渡す名前/値ペア リストです。

(継承元 ManagementOptions)
Timeout

操作に適用するタイムアウトを取得または設定します。 コレクションを返す操作では、このタイムアウトはその操作自体ではなく、結果として得られるコレクションの列挙に適用されます。操作自体に適用するには、ReturnImmediately プロパティを使用します。 このプロパティは、操作が半同期的に実行されることを示すために使用されます。

(継承元 ManagementOptions)

メソッド

Clone()

オブジェクトのコピーを返します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象