ManagementObject.Get Method (ManagementOperationObserver)

 

Binds to the management object asynchronously.

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

Public Sub Get (
	watcher As ManagementOperationObserver
)

Parameters

watcher
Type: System.Management.ManagementOperationObserver

The object to receive the results of the operation as events.

The method will issue the request to get the object and then will immediately return. The results of the operation will then be delivered through events being fired on the watcher object provided.

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 calls the Get method to asynchronously get an instance of the ManagementObject class.

Imports System
Imports System.Management

Class AsyncGetExample

    Public Sub New()

        Dim o As New ManagementObject( _
            "Win32_Process.Name=""notepad.exe""")

        'Set up handlers for asynchronous get
        Dim ob As New ManagementOperationObserver
        AddHandler ob.Completed, AddressOf Me.Done

        'Get the object asynchronously
        o.Get(ob)

        'Wait until operation is completed
        While Not Me.Completed
            System.Threading.Thread.Sleep(1000)
        End While

        'Here you can use the object

    End Sub

    Private _completed As Boolean = False

    Private Sub Done(ByVal sender As Object, _
        ByVal e As CompletedEventArgs)
        Console.WriteLine("async Get completed !")
        _completed = True
    End Sub

    Private ReadOnly Property Completed() As Boolean
        Get
            Return _completed
        End Get
    End Property

    Public Overloads Shared Function Main( _
        ByVal args() As String) As Integer

        Dim example As New AsyncGetExample

        Return 0

    End Function


End Class

.NET Framework
Available since 1.1
Return to top
Show: