EventQuery 클래스

정의

WMI 이벤트 쿼리를 나타냅니다.

public ref class EventQuery : System::Management::ManagementQuery
public class EventQuery : System.Management.ManagementQuery
type EventQuery = class
    inherit ManagementQuery
Public Class EventQuery
Inherits ManagementQuery
상속
EventQuery
파생

예제

다음 예제에서는 클라이언트의 경우 인스턴스의 알림을 수신 하는 방법을 보여 줍니다 Win32_Process 이벤트 클래스 이므로 만들어집니다 __InstanceCreationEvent합니다. 자세한 내용은 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
        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(String)

지정된 쿼리에 대한 EventQuery 클래스의 새 인스턴스를 초기화합니다.

EventQuery(String, String)

지정된 언어와 쿼리에 대한 EventQuery 클래스의 새 인스턴스를 초기화합니다.

속성

QueryLanguage

쿼리 문자열에서 사용되는 쿼리 언어를 가져오거나 설정합니다. 쿼리 언어는 쿼리 문자열의 형식을 정의합니다.

(다음에서 상속됨 ManagementQuery)
QueryString

텍스트 형식의 쿼리를 가져오거나 설정합니다.

(다음에서 상속됨 ManagementQuery)

메서드

Clone()

개체의 복사본을 반환합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ParseQuery(String)

쿼리 문자열을 구문 분석하고 속성 값을 적절하게 설정합니다. 쿼리가 올바르면 쿼리의 클래스 이름 속성과 조건 속성이 구문 분석됩니다.

(다음에서 상속됨 ManagementQuery)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상