EventWatcherOptions クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
管理イベント監視のオプションを指定します。
public ref class EventWatcherOptions : System::Management::ManagementOptions
public class EventWatcherOptions : System.Management.ManagementOptions
type EventWatcherOptions = class
inherit ManagementOptions
Public Class EventWatcherOptions
Inherits ManagementOptions
- 継承
例
次の例は、イベント クラスが__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 コンテキスト オブジェクトを取得または設定します。 これは、カスタマイズされた操作のコンテキスト情報をサポートする WMI プロバイダーに渡される名前と値のペアの一覧です。 (継承元 ManagementOptions) |
| Timeout |
操作に適用するタイムアウトを取得または設定します。 コレクションを返す操作の場合、このタイムアウトは、操作自体ではなく、結果のコレクションを通じて列挙体に適用されることに注意してください (後者には ReturnImmediately プロパティが使用されます)。 このプロパティは、操作を半同期的に実行する必要があることを示すために使用されます。 (継承元 ManagementOptions) |
メソッド
| 名前 | 説明 |
|---|---|
| Clone() |
オブジェクトのコピーを返します。 |
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |