AsyncCompletedEventHandler 代理人

定義

表示將處理非同步作業之 MethodNameCompleted 事件的方法。Represents the method that will handle the MethodNameCompleted event of an asynchronous operation.

public delegate void AsyncCompletedEventHandler(System::Object ^ sender, AsyncCompletedEventArgs ^ e);
public delegate void AsyncCompletedEventHandler(object sender, AsyncCompletedEventArgs e);
type AsyncCompletedEventHandler = delegate of obj * AsyncCompletedEventArgs -> unit
Public Delegate Sub AsyncCompletedEventHandler(sender As Object, e As AsyncCompletedEventArgs)

參數

sender
Object

事件的來源。The source of the event.

e
AsyncCompletedEventArgs

包含事件資料的 AsyncCompletedEventArgsAn AsyncCompletedEventArgs that contains the event data.

繼承
AsyncCompletedEventHandler

範例

如需AsyncCompletedEventHandler委派的程式碼範例, 請參閱System.ComponentModel.AsyncCompletedEventArgs類別中的範例。For a code example of the AsyncCompletedEventHandler delegate, see the example in the System.ComponentModel.AsyncCompletedEventArgs class.

備註

當您建立 AsyncCompletedEventHandler 委派 (Delegate) 時,就可以識別即將處理此事件的方法。When you create an AsyncCompletedEventHandler delegate, you identify the method that will handle the event. 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。To associate the event with your event handler, add an instance of the delegate to the event. 事件處理常式方法會在事件發生時呼叫, 除非您移除委派。The event-handler method is called whenever the event occurs, unless you remove the delegate. 如需事件處理常式委派的詳細資訊, 請參閱處理和引發事件For more information about event-handler delegates, see Handling and Raising Events.

在您的元件中, 如果是名為方法的非同步方法, 您將會有對應的方法名稱Completed CompletedEventArgs事件和選擇性的方法名稱類別。For an asynchronous method, called MethodName, in your component, you will have a corresponding MethodNameCompleted event, and an optional MethodNameCompletedEventArgs class.

對於支援多個並行調用其非同步方法的元件, 用戶端可以提供唯一的 token 或工作識別碼, 以區別哪個非同步工作會引發特定事件。For a component that supports multiple concurrent invocations of its asynchronous methods, the client can supply a unique token, or task ID, to distinguish which asynchronous task is raising particular events. 用戶端AsyncCompletedEventHandler可以AsyncCompletedEventArgs.UserState讀取屬性來判斷哪一項工作正在報告完成。The client's AsyncCompletedEventHandler can read the AsyncCompletedEventArgs.UserState property to determine which task is reporting completion. 您的執行應使用System.ComponentModel.AsyncOperationManagerSystem.ComponentModel.AsyncOperation建立, 使用戶端的工作識別碼與暫止的非同步工作產生關聯。Your implementation should use the System.ComponentModel.AsyncOperationManager to create an System.ComponentModel.AsyncOperation that associates the client's task IDs with pending asynchronous tasks.

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。Gets an object that represents the method represented by the specified delegate.

適用於

另請參閱