WqlEventQuery Constructor (String, TimeSpan, String)


Initializes a new instance of the WqlEventQuery class with the specified event class name, polling interval, and condition.

Namespace:   System.Management
Assembly:  System.Management (in System.Management.dll)

public WqlEventQuery(
	string eventClassName,
	TimeSpan withinInterval,
	string condition


Type: System.String

The name of the event class to query.

Type: System.TimeSpan

A TimeSpan value specifying the latency acceptable for receiving this event. This value is used in cases where there is no explicit event provider for the query requested and WMI is required to poll for the condition. This interval is the maximum amount of time that can pass before notification of an event must be delivered.

Type: System.String

The condition to apply to events of the specified class.

Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

The following example creates the event query: "SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA Win32_Service ", which sends notification of the creation of Win32_Service instances, with a 10-second polling interval.

using System;
using System.Management;

public class EventSample 
    public static void Main(string[] args) 
        // Requests notification of the creation
        // of Win32_Service instances with
        // a 10 second allowed latency.
        WqlEventQuery q = new WqlEventQuery("__InstanceCreationEvent", 
            new TimeSpan(0,0,10), 
            "TargetInstance isa 'Win32_Service'");


.NET Framework
Available since 1.1
Return to top