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

예제

다음 예제에서는 이벤트 클래스가 __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
        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

생성자

Name Description
ManagementEventWatcher()

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

ManagementEventWatcher(EventQuery)

WMI 이벤트 쿼리가 제공되면 클래스의 ManagementEventWatcher 새 인스턴스를 초기화합니다.

ManagementEventWatcher(ManagementScope, EventQuery, EventWatcherOptions)

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

ManagementEventWatcher(ManagementScope, EventQuery)

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

ManagementEventWatcher(String, String, EventWatcherOptions)

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

ManagementEventWatcher(String, String)

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

ManagementEventWatcher(String)

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

속성

Name Description
CanRaiseEvents

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

(다음에서 상속됨 Component)
Container

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

(다음에서 상속됨 Component)
DesignMode

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

(다음에서 상속됨 Component)
Events

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

(다음에서 상속됨 Component)
Options

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

Query

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

Scope

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

Site

ISite를 가져오거나 Component의 값을 설정합니다.

(다음에서 상속됨 Component)

메서드

Name Description
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()

String(있는 경우)의 Component이름을 포함하는 값을 반환합니다. 이 메서드는 재정의해서는 안 됩니다.

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

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

이벤트

Name Description
Disposed

구성 요소가 메서드 호출에 Dispose() 의해 삭제될 때 발생합니다.

(다음에서 상속됨 Component)
EventArrived

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

Stopped

구독이 취소될 때 발생합니다.

적용 대상