WqlEventQuery.WithinInterval Vlastnost

Definice

Získá nebo nastaví interval dotazování, který se má použít v tomto dotazu.

public:
 property TimeSpan WithinInterval { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan WithinInterval { get; set; }
member this.WithinInterval : TimeSpan with get, set
Public Property WithinInterval As TimeSpan

Hodnota vlastnosti

TimeSpan Vrátí hodnotu obsahující interval dotazování použitý v dotazu události.

Příklady

Následující příklad inicializuje nový WqlEventQuery , který představuje dotaz: "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA "Win32_Process".

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 new process being created
        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(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 seconds of 
        ' a process being created
        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(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

Poznámky

Tato vlastnost by měla být nastavena pouze v případech, kdy pro požadovanou událost neexistuje žádný zprostředkovatel událostí a rozhraní WMI se vyžaduje k dotazování na požadovanou podmínku.

Nastavení této hodnoty vlastnosti přepíše všechny předchozí hodnoty uložené v objektu. Řetězec dotazu se znovu sestaví tak, aby odrážel nový interval.

Hodnota vlastnosti

Null, pokud neexistuje žádné dotazování; v opačném případě platí platná TimeSpan hodnota, pokud je požadováno dotazování.

Zabezpečení rozhraní .NET Framework

Plný vztah důvěryhodnosti pro okamžitého volajícího. Tento člen nemůže být používán částečně důvěryhodným kódem. Další informace naleznete v tématu Použití knihoven z částečně důvěryhodného kódu.

Platí pro