EventWatcherOptions Sınıf

Tanım

Yönetim olayı izleme seçeneklerini belirtir.

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

Örnekler

Aşağıdaki örnekte, olay sınıfı __InstanceCreationEvent olduğundan bir Win32_Process örneği oluşturulduğunda istemcinin nasıl bildirim aldığı gösterilmektedir. Daha fazla bilgi için Windows Yönetim Araçları belgelerine bakın. İstemci, yöntemini çağırarak WaitForNextEvent olayları zaman uyumlu olarak alır. Bu örnek, örnek kod çalışırken Not Defteri gibi bir işlem başlatılarak test edilebilir.

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

Oluşturucular

Name Description
EventWatcherOptions()

Varsayılan değerleri kullanarak olay izleme için sınıfının yeni bir örneğini EventWatcherOptions başlatır. Bu, parametresiz oluşturucudur.

EventWatcherOptions(ManagementNamedValueCollection, TimeSpan, Int32)

Verilen değerlerle sınıfının yeni bir örneğini EventWatcherOptions başlatır.

Özellikler

Name Description
BlockSize

Blok işlemleri için blok boyutunu alır veya ayarlar. Olayları beklerken, bu değer döndürülmeden önce kaç olay bekliyeceği belirtir.

Context

WMI bağlam nesnesini alır veya ayarlar. Bu, özelleştirilmiş işlem için bağlam bilgilerini destekleyen bir WMI sağlayıcısına geçirilecek bir ad-değer çiftleri listesidir.

(Devralındığı yer: ManagementOptions)
Timeout

İşleme uygulanacak zaman aşımını alır veya ayarlar. Koleksiyon döndüren işlemler için bu zaman aşımının işlemin kendisi ReturnImmediately (ikincisi için kullanılır) değil, sonuçta elde edilen koleksiyon aracılığıyla numaralandırma için geçerli olduğunu unutmayın. Bu özellik, işlemin yarı zaman uyumlu olarak gerçekleştirilmesi gerektiğini belirtmek için kullanılır.

(Devralındığı yer: ManagementOptions)

Yöntemler

Name Description
Clone()

Nesnenin bir kopyasını döndürür.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır