EventWatcherOptions 클래스

정의

관리 이벤트 조사에 대한 옵션을 지정합니다.

public ref class EventWatcherOptions : System::Management::ManagementOptions
public class EventWatcherOptions : System.Management.ManagementOptions
type EventWatcherOptions = class
    inherit ManagementOptions
Public Class EventWatcherOptions
Inherits ManagementOptions
상속
EventWatcherOptions

예제

다음 예제에서는 클라이언트의 경우 인스턴스의 알림을 수신 하는 방법을 보여 줍니다 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
        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)

적용 대상