CompletedEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
保留 Completed 事件的事件資料。
public ref class CompletedEventArgs : System::Management::ManagementEventArgs
public class CompletedEventArgs : System.Management.ManagementEventArgs
type CompletedEventArgs = class
inherit ManagementEventArgs
Public Class CompletedEventArgs
Inherits ManagementEventArgs
- 繼承
範例
下列範例會以異步方式呼叫 方法。 會呼叫 Win32_Process.Create 方法來建立 Calc.exe 的新程式。
using System;
using System.Management;
public class InvokeMethodAsync
{
private bool isComplete = false;
private ManagementBaseObject returnObject;
public InvokeMethodAsync()
{
// Get the object on which the method
// will be invoked
ManagementClass processClass =
new ManagementClass("Win32_Process");
// Create a results and completion handler
ManagementOperationObserver handler =
new ManagementOperationObserver();
handler.Completed +=
new CompletedEventHandler(this.Completed);
// Invoke method asynchronously
ManagementBaseObject inParams =
processClass.GetMethodParameters("Create");
inParams["CommandLine"] = "calc.exe";
processClass.InvokeMethod(
handler, "Create", inParams, null);
// Do something while method is executing
while(!this.IsComplete)
{
System.Threading.Thread.Sleep(1000);
}
}
// Property allows accessing the result
// object in the main function
private ManagementBaseObject ReturnObject
{
get
{
return returnObject;
}
}
// Delegate called when the method completes
// and results are available
private void NewObject(object sender,
ObjectReadyEventArgs e)
{
Console.WriteLine("New Object arrived!");
returnObject = e.NewObject;
}
// Used to determine whether the method
// execution has completed
private bool IsComplete
{
get
{
return isComplete;
}
}
private void Completed(object sender,
CompletedEventArgs e)
{
isComplete = true;
Console.WriteLine("Method invoked.");
}
public static void Main()
{
InvokeMethodAsync invokeMethod = new InvokeMethodAsync();
return;
}
}
Imports System.Management
Public Class InvokeMethodAsync
Private isFinished As Boolean = False
Private returnObj As ManagementBaseObject
Public Sub New()
' Get the object on which the method
' will be invoked
Dim processClass As ManagementClass = _
New ManagementClass("Win32_Process")
' Create a results and completion handler
Dim handler As ManagementOperationObserver = _
New ManagementOperationObserver
AddHandler handler.Completed, _
AddressOf Me.Completed
' Invoke method asynchronously
Dim inParams As ManagementBaseObject = _
processClass.GetMethodParameters("Create")
inParams("CommandLine") = "calc.exe"
processClass.InvokeMethod( _
handler, "Create", inParams, Nothing)
' Do something while method is executing
While (Not Me.IsComplete)
System.Threading.Thread.Sleep(1000)
End While
End Sub
' Property allows accessing the result
' object in the main function
Private Function ReturnObject() As ManagementBaseObject
Return returnObj
End Function
' Delegate called when the method completes
' and results are available
Private Sub NewObject(ByVal sender As Object, _
ByVal e As ObjectReadyEventArgs)
Console.WriteLine("New Object arrived!")
returnObj = e.NewObject
End Sub
' Used to determine whether the method
' execution has completed
Private Function IsComplete() As Boolean
Return isFinished
End Function
Private Sub Completed(ByVal sender As Object, _
ByVal e As CompletedEventArgs)
isFinished = True
Console.WriteLine("Completed method invocation.")
End Sub
Public Shared Function _
Main(ByVal args() As String) As Integer
Dim invokeMethod As New InvokeMethodAsync
Return 0
End Function
End Class
屬性
Context |
取得從觸發事件作業回應的作業內容。 (繼承來源 ManagementEventArgs) |
Status |
取得作業的完成狀態。 |
StatusObject |
取得 WMI 物件中的額外狀態資訊。 這可能是 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |