EventQuery Classe

Definição

Representa uma consulta de evento do WMI.Represents a WMI event query.

public ref class EventQuery : System::Management::ManagementQuery
public class EventQuery : System.Management.ManagementQuery
type EventQuery = class
    inherit ManagementQuery
Public Class EventQuery
Inherits ManagementQuery
Herança
EventQuery
Derivado

Exemplos

O exemplo a seguir mostra como o cliente recebe a notificação quando uma instância de Win32_Process é criada porque a classe de evento é __InstanceCreationEvent.The following example shows how the client receives notification when an instance of Win32_Process is created because the event class is __InstanceCreationEvent. Para obter mais informações, consulte a documentação do Instrumentação de gerenciamento do Windows .For more information, see the Windows Management Instrumentation documentation. O cliente recebe eventos de forma síncrona chamando WaitForNextEvent o método.The client receives events synchronously by calling the WaitForNextEvent method. Este exemplo pode ser testado com o início de um processo, como o bloco de notas, enquanto o código de exemplo está em execução.This example can be tested by starting a process, such as Notepad, while the example code is running.

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

Construtores

EventQuery()

Inicializa uma nova instância da classe EventQuery.Initializes a new instance of the EventQuery class. Esse é o construtor sem parâmetros.This is the parameterless constructor.

EventQuery(String)

Inicializa uma nova instância da classe EventQuery para a consulta especificada.Initializes a new instance of the EventQuery class for the specified query.

EventQuery(String, String)

Inicializa uma nova instância da classe EventQuery para o idioma e consulta especificados.Initializes a new instance of the EventQuery class for the specified language and query.

Propriedades

QueryLanguage

Obtém ou define o idioma de consulta usado na cadeia de caracteres de consulta, definindo o formato da cadeia de caracteres de consulta.Gets or sets the query language used in the query string, defining the format of the query string.

(Herdado de ManagementQuery)
QueryString

Obtém ou define a consulta em formato de texto.Gets or sets the query in text format.

(Herdado de ManagementQuery)

Métodos

Clone()

Retorna uma cópia do objeto.Returns a copy of the object.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ParseQuery(String)

Analisa a cadeia de caracteres de consulta e define os valores de propriedade adequadamente.Parses the query string and sets the property values accordingly. Se a consulta for válida, a propriedade de nome de classe e a propriedade de condição da consulta serão analisadas.If the query is valid, the class name property and condition property of the query will be parsed.

(Herdado de ManagementQuery)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Aplica-se a