Share via


ManagementObject.Get Metodo

Definizione

Esegue l'associazione all'oggetto di gestione.

Overload

Get()

Associa le informazioni sulle classi WMI all'oggetto di gestione.

Get(ManagementOperationObserver)

Esegue l'associazione all'oggetto di gestione in modo asincrono.

Commenti

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Get()

Origine:
ManagementObject.cs
Origine:
ManagementObject.cs
Origine:
ManagementObject.cs

Associa le informazioni sulle classi WMI all'oggetto di gestione.

public:
 void Get();
public void Get ();
member this.Get : unit -> unit
Public Sub Get ()

Esempio

Nell'esempio seguente viene chiamato il metodo per ottenere un'istanza Get della ManagementObject classe.

using System;
using System.Management;

class Sample
{
    public static int Main(string[] args)
    {
        ManagementObject o =
            new ManagementObject("MyClass.Name='abc'");

        //this causes an implicit Get().
        string s = o["Name"].ToString();

        Console.WriteLine(s);

        //or :

        ManagementObject mObj =
            new ManagementObject("MyClass.Name= 'abc'");
        mObj.Get(); //explicitly
        // Now it is faster because the object
        // has already been retrieved.
        string property = mObj["Name"].ToString();

        Console.WriteLine(property);

        return 0;
    }
}
Imports System.Management

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

        Dim o As New ManagementObject( _
            "MyClass.Name=""abc""")

        'this causes an implicit Get().
        Dim s As String = o("SomeProperty")

        Console.WriteLine(s)

        'or :

        Dim mObj As New ManagementObject("MyClass.Name= ""abc""")
        mObj.Get()  'explicitly 
        ' Now it is faster because the object
        ' has already been retrieved.
        Dim p As String = mObj("SomeProperty")

        Console.WriteLine(p)

        Return 0
    End Function
End Class

Commenti

Il metodo viene richiamato in modo implicito al primo tentativo di ottenere o impostare informazioni sull'oggetto WMI. Può anche essere richiamato in modo esplicito alla discrezione dell'utente, per controllare meglio i tempi e la modalità di recupero.

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Si applica a

Get(ManagementOperationObserver)

Origine:
ManagementObject.cs
Origine:
ManagementObject.cs
Origine:
ManagementObject.cs

Esegue l'associazione all'oggetto di gestione in modo asincrono.

public:
 void Get(System::Management::ManagementOperationObserver ^ watcher);
public void Get (System.Management.ManagementOperationObserver watcher);
member this.Get : System.Management.ManagementOperationObserver -> unit
Public Sub Get (watcher As ManagementOperationObserver)

Parametri

watcher
ManagementOperationObserver

Oggetto che riceverà i risultati dell'operazione in forma di eventi.

Esempio

Nell'esempio seguente viene chiamato il Get metodo per ottenere in modo asincrono un'istanza della ManagementObject classe.

using System;
using System.Management;

public class AsyncGetExample
{
    public AsyncGetExample()
    {
        ManagementObject o =
            new ManagementObject(
            "Win32_Process.Name='notepad.exe'");

        // Set up handlers for asynchronous get
        ManagementOperationObserver ob =
            new ManagementOperationObserver();
        ob.Completed += new
            CompletedEventHandler(this.Done);

        // Get the object asynchronously
        o.Get(ob);

        // Wait until operation is completed
        while (!this.Completed)
            System.Threading.Thread.Sleep (1000);

        // Here you can use the object
    }

    private bool completed = false;

    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 example =
            new AsyncGetExample();
    }
}
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

Commenti

Il metodo emetterà la richiesta per ottenere l'oggetto e quindi restituirà immediatamente. I risultati dell'operazione verranno quindi recapitati tramite eventi generati sull'oggetto watcher fornito.

Sicurezza di .NET Framework

Attendibilità totale per il chiamante immediato. Impossibile utilizzare questo membro in codice parzialmente attendibile. Per altre informazioni, vedere Uso di librerie da codice parzialmente attendibile.

Si applica a