EventQuery EventQuery EventQuery EventQuery Class

定義

WMI イベント クエリを表します。Represents a WMI event query.

public ref class EventQuery : System::Management::ManagementQuery
public class EventQuery : System.Management.ManagementQuery
type EventQuery = class
    inherit ManagementQuery
Public Class EventQuery
Inherits ManagementQuery
継承
派生

次の例は、イベントクラスが __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
        EventQuery query = new EventQuery();
        query.QueryString = "SELECT * FROM" +
            " __InstanceCreationEvent WITHIN 1 " + 
            "WHERE TargetInstance isa \"Win32_Process\"";

        // Initialize an event watcher and subscribe to events 
        // that match this query
        ManagementEventWatcher watcher =
            new ManagementEventWatcher(query);
        // times out watcher.WaitForNextEvent in 5 seconds
        watcher.Options.Timeout = new TimeSpan(0,0,5);
      
        // 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 New EventQuery
        query.QueryString = "SELECT * FROM" & _
            " __InstanceCreationEvent WITHIN 1 " & _
            "WHERE TargetInstance isa ""Win32_Process"""

        ' Initialize an event watcher and subscribe to events 
        ' that match this query
        Dim watcher As New ManagementEventWatcher(query)
        ' times watcher.WaitForNextEvent in 5 seconds
        watcher.Options.Timeout = New TimeSpan(0, 0, 50)

        ' 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

コンストラクター

EventQuery() EventQuery() EventQuery() EventQuery()

EventQuery クラスの新しいインスタンスを初期化します。Initializes a new instance of the EventQuery class. これはパラメーターなしのコンストラクターです。This is the parameterless constructor.

EventQuery(String) EventQuery(String) EventQuery(String) EventQuery(String)

指定したクエリの EventQuery クラスの新しいインスタンスを初期化します。Initializes a new instance of the EventQuery class for the specified query.

EventQuery(String, String) EventQuery(String, String) EventQuery(String, String) EventQuery(String, String)

指定した言語とクエリの EventQuery クラスの新しいインスタンスを初期化します。Initializes a new instance of the EventQuery class for the specified language and query.

メソッド

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)
ParseQuery(String) ParseQuery(String) ParseQuery(String) ParseQuery(String)

クエリ文字列を解析し、その結果に応じてプロパティ値を設定します。Parses the query string and sets the property values accordingly. クエリが有効な場合は、クエリのクラス名プロパティおよび条件プロパティが解析されます。If the query is valid, the class name property and condition property of the query will be parsed.

(Inherited from ManagementQuery)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

プロパティ

QueryLanguage QueryLanguage QueryLanguage QueryLanguage

クエリ文字列の書式を定義して、クエリ文字列で使用するクエリ言語を取得または設定します。Gets or sets the query language used in the query string, defining the format of the query string.

(Inherited from ManagementQuery)
QueryString QueryString QueryString QueryString

テキスト形式でクエリを取得または設定します。Gets or sets the query in text format.

(Inherited from ManagementQuery)

適用対象