Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ManagementOperationObserver Class
Collapse the table of content
Expand the table of content

ManagementOperationObserver Class

Used to manage asynchronous operations and handle management information and events received asynchronously.

For a list of all members of this type, see ManagementOperationObserver Members.

System.Object
   System.Management.ManagementOperationObserver

[Visual Basic]
Public Class ManagementOperationObserver
[C#]
public class ManagementOperationObserver
[C++]
public __gc class ManagementOperationObserver
[JScript]
public class ManagementOperationObserver

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Example

[C#] 
using System; 
using System.Management; 

// This sample demonstrates how to read a ManagementObject asychronously 
// using the ManagementOperationObserver object. 

class Sample_ManagementOperationObserver {
    public static int Main(string[] args) {

        //Set up a handler for the asynchronous callback
        ManagementOperationObserver observer = new ManagementOperationObserver(); 
        MyHandler completionHandler = new MyHandler(); 
        observer.Completed += new CompletedEventHandler(completionHandler.Done); 

        //Invoke the asynchronous read of the object
        ManagementObject disk = new ManagementObject("Win32_logicaldisk='C:'"); 
        disk.Get(observer); 

        //For the purpose of this sample, we keep the main 
        // thread alive until the asynchronous operation is completed. 

        while (!completionHandler.IsComplete) { 
            System.Threading.Thread.Sleep(500); 
        } 

        Console.WriteLine("Size= " + disk["Size"] + " bytes."); 

        return 0; 
    } 

    public class MyHandler 
    {
        private bool isComplete = false;
 
        public void Done(object sender, CompletedEventArgs e) { 
            isComplete = true;
        }

        public bool IsComplete {
            get {
                return isComplete;
            }
        }
    }
}
   
[Visual Basic] 
Imports System
Imports System.Management

' This sample demonstrates how to read a ManagementObject asychronously
' using the ManagementOperationObserver object.

Class Sample_ManagementOperationObserver
    Overloads Public Shared Function Main(args() As String) As Integer

        'Set up a handler for the asynchronous callback
        Dim observer As New ManagementOperationObserver()
        Dim completionHandler As New MyHandler()
        AddHandler observer.Completed, AddressOf completionHandler.Done
      
        ' Invoke the object read asynchronously
        Dim disk As New ManagementObject("Win32_logicaldisk='C:'")
        disk.Get(observer)

        ' For the purpose of this sample, we keep the main
        ' thread alive until the asynchronous operation is finished.
        While Not completionHandler.IsComplete Then
            System.Threading.Thread.Sleep(500)
        End While
       
        Console.WriteLine("Size = " + disk("Size").ToString() & " bytes")
      
        Return 0
    End Function

    Public Class MyHandler
        Private _isComplete As Boolean = False
   
        Public Sub Done(sender As Object, e As CompletedEventArgs)
            _isComplete = True
        End Sub 'Done

        Public ReadOnly Property IsComplete() As Boolean
            Get
                Return _isComplete
            End Get
        End Property
    End Class
End Class
   

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Management

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

ManagementOperationObserver Members | System.Management Namespace

Show:
© 2015 Microsoft