EventWatcherOptions EventWatcherOptions EventWatcherOptions EventWatcherOptions Class

定義

管理イベント ウォッチのオプションを指定します。Specifies options for management event watching.

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

次の例は、イベントクラスが __InstanceCreationEventであるため、 Win32_Processのインスタンスが作成されたときにクライアントが通知を受信する方法を示しています。The following example shows how the client receives notification when an instance of Win32_Process is created because the event class is __InstanceCreationEvent. 詳細については、 Windows Management Instrumentationのドキュメントを参照してください。For more information, see the Windows Management Instrumentation documentation. クライアントは WaitForNextEvent メソッドを呼び出して、イベントを同期的に受信します。The client receives events synchronously by calling the WaitForNextEvent method. この例は、コード例の実行中にメモ帳などのプロセスを開始することでテストできます。This example can be tested by starting a process, such as Notepad, while the example code is running.

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() EventWatcherOptions()

イベント ウォッチのための EventWatcherOptions クラスの新しいインスタンスを、既定値を使用して初期化します。Initializes a new instance of the EventWatcherOptions class for event watching, using default values. これはパラメーターなしのコンストラクターです。This is the parameterless constructor.

EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32) EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32) EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32) EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32)

指定した値を使用して、EventWatcherOptions クラスの新しいインスタンスを初期化します。Initializes a new instance of the EventWatcherOptions class with the given values.

プロパティ

BlockSize BlockSize BlockSize BlockSize

ブロック操作のブロック サイズを取得または設定します。Gets or sets the block size for block operations. イベントを待機する場合、この値は制御を戻す前に待機するイベント数を指定します。When waiting for events, this value specifies how many events to wait for before returning.

Context Context Context Context

WMI (Windows Management Instrumentation) コンテキスト オブジェクトを取得または設定します。Gets or sets a WMI context object. これは、カスタマイズされた操作のためのコンテキスト情報をサポートしている WMI プロバイダーに渡す名前/値ペア リストです。This is a name-value pairs list to be passed through to a WMI provider that supports context information for customized operation.

(Inherited from ManagementOptions)
Timeout Timeout Timeout Timeout

操作に適用するタイムアウトを取得または設定します。Gets or sets the time-out to apply to the operation. コレクションを返す操作では、このタイムアウトはその操作自体ではなく、結果として得られるコレクションの列挙に適用されます。操作自体に適用するには、ReturnImmediately プロパティを使用します。Note that for operations that return collections, this time-out applies to the enumeration through the resulting collection, not the operation itself (the ReturnImmediately property is used for the latter). このプロパティは、操作が半同期的に実行されることを示すために使用されます。This property is used to indicate that the operation should be performed semi-synchronously.

(Inherited from ManagementOptions)

メソッド

Clone() Clone() Clone() Clone()

オブジェクトのコピーを返します。Returns a copy of the object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象