Share via


EventQuery Sınıf

Tanım

WMI olay sorgusunu temsil eder.

public ref class EventQuery : System::Management::ManagementQuery
public class EventQuery : System.Management.ManagementQuery
type EventQuery = class
    inherit ManagementQuery
Public Class EventQuery
Inherits ManagementQuery
Devralma
EventQuery
Türetilmiş

Ö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
        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

Oluşturucular

EventQuery()

EventQuery sınıfının yeni bir örneğini başlatır. Bu, parametresiz oluşturucudur.

EventQuery(String)

Belirtilen sorgu için sınıfının yeni bir örneğini EventQuery başlatır.

EventQuery(String, String)

Belirtilen dil ve sorgu için sınıfının yeni bir örneğini EventQuery başlatır.

Özellikler

QueryLanguage

Sorgu dizesinin biçimini tanımlayarak sorgu dizesinde kullanılan sorgu dilini alır veya ayarlar.

(Devralındığı yer: ManagementQuery)
QueryString

Sorguyu metin biçiminde alır veya ayarlar.

(Devralındığı yer: ManagementQuery)

Yöntemler

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

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

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

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ParseQuery(String)

Sorgu dizesini ayrıştırıp özellik değerlerini buna göre ayarlar. Sorgu geçerliyse, sorgunun sınıf adı özelliği ve koşul özelliği ayrıştırılır.

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

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

(Devralındığı yer: Object)

Şunlara uygulanır