次の方法で共有


ManagementOperationObserver クラス

非同期操作の管理と管理情報の処理、および非同期的に受け取ったイベントの処理に使用されます。

この型のすべてのメンバの一覧については、ManagementOperationObserver メンバ を参照してください。

System.Object
   System.Management.ManagementOperationObserver

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

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

使用例

 
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] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Management

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Management (System.Management.dll 内)

参照

ManagementOperationObserver メンバ | System.Management 名前空間