ManagementEventWatcher 클래스

정의

지정된 이벤트 쿼리에 따라 임시 이벤트 알림을 신청합니다.

public ref class ManagementEventWatcher : System::ComponentModel::Component
public class ManagementEventWatcher : System.ComponentModel.Component
type ManagementEventWatcher = class
    inherit Component
Public Class ManagementEventWatcher
Inherits Component
상속
ManagementEventWatcher

예제

다음 예제에서는 클라이언트의 경우 인스턴스의 알림을 수신 하는 방법을 보여 줍니다 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
        WqlEventQuery query =
            new WqlEventQuery("__InstanceCreationEvent",
            new TimeSpan(0,0,1),
            "TargetInstance isa \"Win32_Process\"");

        // Initialize an event watcher and subscribe to events
        // that match this query
        ManagementEventWatcher watcher =
            new ManagementEventWatcher();
        watcher.Query = 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 WqlEventQuery( _
            "__InstanceCreationEvent", _
            New TimeSpan(0, 0, 1), _
            "TargetInstance isa ""Win32_Process""")

        ' Initialize an event watcher and subscribe to events 
        ' that match this query
        Dim watcher As New ManagementEventWatcher
        watcher.Query = query
        ' times 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.")
        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

생성자

ManagementEventWatcher()

ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다. 추가로 초기화하려면 개체의 속성을 설정합니다. 이는 매개 변수가 없는 생성자입니다.

ManagementEventWatcher(EventQuery)

WMI 이벤트 쿼리에 따라 ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다.

ManagementEventWatcher(ManagementScope, EventQuery)

지정된 WMI 이벤트 쿼리와 일치하는 이벤트를 수신하는 ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다.

ManagementEventWatcher(ManagementScope, EventQuery, EventWatcherOptions)

지정된 옵션에 따라, 지정된 WMI 이벤트 쿼리와 일치하는 이벤트를 수신하는 ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다. 이 변형에서는 쿼리와 범위가 개체로 지정됩니다. 옵션 개체에서는 시간 제한 및 컨텍스트 정보와 같은 옵션을 지정할 수 있습니다.

ManagementEventWatcher(String)

WMI 이벤트 쿼리가 문자열 형태로 지정되면 ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다.

ManagementEventWatcher(String, String)

지정된 WMI 이벤트 쿼리와 일치하는 이벤트를 수신하는 ManagementEventWatcher 클래스의 새 인스턴스를 초기화합니다. 이 변형에서는 쿼리와 범위가 문자열로 지정됩니다.

ManagementEventWatcher(String, String, EventWatcherOptions)

지정된 옵션에 따라 지정된 WMI 이벤트 쿼리를 준수하는 이벤트를 수신 대기하는 클래스의 ManagementEventWatcher 새 instance 초기화합니다. 이 변형에서는 쿼리와 범위가 문자열로 지정됩니다. 옵션 개체에서는 시간 제한 및 컨텍스트 정보와 같은 옵션을 지정할 수 있습니다.

속성

CanRaiseEvents

구성 요소가 이벤트를 발생시킬 수 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
Container

IContainer을 포함하는 Component를 가져옵니다.

(다음에서 상속됨 Component)
DesignMode

Component가 현재 디자인 모드인지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 Component)
Events

Component에 연결된 이벤트 처리기의 목록을 가져옵니다.

(다음에서 상속됨 Component)
Options

이벤트를 조사하는 데 사용할 옵션을 가져오거나 설정합니다.

Query

이벤트에 적용할 기준을 가져오거나 설정합니다.

Scope

이벤트를 조사할 범위(네임스페이스 또는 범위)를 가져오거나 설정합니다.

Site

ComponentISite를 가져오거나 설정합니다.

(다음에서 상속됨 Component)

메서드

CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시 생성에 필요한 모든 관련 정보가 들어 있는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Dispose()

Component에서 사용하는 모든 리소스를 해제합니다.

(다음에서 상속됨 Component)
Dispose(Boolean)

Component에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

(다음에서 상속됨 Component)
Equals(Object)

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

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

아직 해결되지 않은 호출을 해제합니다. 개체의 소멸자입니다. C#에서 종료자는 소멸자 구문을 사용하여 표현됩니다.

GetHashCode()

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

(다음에서 상속됨 Object)
GetLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 현재의 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetService(Type)

Component 또는 해당 Container에서 제공하는 서비스를 나타내는 개체를 반환합니다.

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

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

(다음에서 상속됨 Object)
InitializeLifetimeService()
사용되지 않음.

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

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

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

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

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Start()

지정된 쿼리를 사용하여 이벤트에 등록하고 EventArrived 이벤트를 통해 비동기적으로 배달합니다.

Stop()

동기적이든지 비동기적이든지 상관없이 등록을 취소합니다.

ToString()

Component의 이름이 포함된 String을 반환합니다(있는 경우). 이 메서드는 재정의할 수 없습니다.

(다음에서 상속됨 Component)
WaitForNextEvent()

지정된 쿼리와 일치하는 다음 이벤트가 도착하기를 기다린 다음 해당 이벤트를 반환합니다.

이벤트

Disposed

Dispose() 메서드를 호출하여 구성 요소를 삭제할 때 발생합니다.

(다음에서 상속됨 Component)
EventArrived

새 이벤트가 도착하면 발생합니다.

Stopped

등록이 취소되면 발생합니다.

적용 대상