Export (0) Print
Expand All

ManagementClass.GetInstances Method (ManagementOperationObserver)

Returns the collection of all instances of the class, asynchronously.

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

public void GetInstances (
	ManagementOperationObserver watcher
)
public void GetInstances (
	ManagementOperationObserver watcher
)
public function GetInstances (
	watcher : ManagementOperationObserver
)
Not applicable.

Parameters

watcher

The object to handle the asynchronous operation's progress.

.NET Framework Security

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 shows how to initialize a ManagementClass variable with a ManagementClass constructor and then get all the instances of a WMI class asynchronously.

using System;
using System.Management;

public class AsyncGetExample
{
    public AsyncGetExample() 
    {
        ManagementClass c = 
            new ManagementClass("Win32_Process");
        ManagementOperationObserver ob =
            new ManagementOperationObserver();
        ob.ObjectReady += new ObjectReadyEventHandler(NewObject);
        ob.Completed += new CompletedEventHandler(Done);

        c.GetInstances(ob);

        while (!Completed)
            System.Threading.Thread.Sleep (1000);

        // Here you can use the object
        
    }

    private bool completed = false;

    private void NewObject(object sender,
        ObjectReadyEventArgs e) 
    {
        Console.WriteLine("New result arrived: {0}",
            ((ManagementObject)(e.NewObject))["Name"]);
    }

    private void Done(object sender,
        CompletedEventArgs e) 
    {
        Console.WriteLine("async Get completed !");
        completed = true;
    }

    private bool Completed 
    { 
        get 
        {
            return completed;
        }
    }

    public static void Main()
    {
        AsyncGetExample asyncGet = new
            AsyncGetExample();

        return;
    }
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft