WaitCallback 代理人

定義

表示執行緒集區執行緒執行的回呼方法。Represents a callback method to be executed by a thread pool thread.

public delegate void WaitCallback(System::Object ^ state);
public delegate void WaitCallback(object state);
[System.Runtime.InteropServices.ComVisible(true)]
public delegate void WaitCallback(object state);
type WaitCallback = delegate of obj -> unit
[<System.Runtime.InteropServices.ComVisible(true)>]
type WaitCallback = delegate of obj -> unit
Public Delegate Sub WaitCallback(state As Object)

參數

state
Object

物件,它包含回呼方法所使用的資訊。An object containing information to be used by the callback method.

繼承
WaitCallback
屬性

備註

WaitCallback 表示您想要線上程上執行的回呼方法 ThreadPoolWaitCallback represents a callback method that you want to execute on a ThreadPool thread. 藉由將您的回呼方法傳遞給函式來建立委派 WaitCallbackCreate the delegate by passing your callback method to the WaitCallback constructor. 您的方法必須有此處所示的簽章。Your method must have the signature shown here.

將委派傳遞給,以將方法排入佇列以執行 WaitCallback ThreadPool.QueueUserWorkItemQueue the method for execution by passing the WaitCallback delegate to ThreadPool.QueueUserWorkItem. 當執行緒集區執行緒變成可用時,就會執行回呼方法。The callback method executes when a thread pool thread becomes available.

注意

Visual Basic 使用者可以省略此 WaitCallback 函式,並在將 AddressOf 回呼方法傳遞給時,直接使用運算子 QueueUserWorkItemVisual Basic users can omit the WaitCallback constructor, and simply use the AddressOf operator when passing the callback method to QueueUserWorkItem. Visual Basic 會自動呼叫正確的委派函式。Visual Basic automatically calls the correct delegate constructor.

如果您想要將資訊傳遞給回呼方法,請建立包含必要資訊的物件,並將它傳遞給 QueueUserWorkItem(WaitCallback, Object) 方法做為第二個引數。If you want to pass information to the callback method, create an object that contains the necessary information and pass it to the QueueUserWorkItem(WaitCallback, Object) method as the second argument. 每次執行回呼方法時,參數就會 state 包含此物件。Each time the callback method executes, the state parameter contains this object.

如需使用委派的範例 WaitCallback ,請參閱 ThreadPool.QueueUserWorkItem 方法。For examples that use the WaitCallback delegate, see the ThreadPool.QueueUserWorkItem method.

如需有關執行緒集區的詳細資訊,請參閱 managed 執行緒集區。For more information about the thread pool, see The managed thread pool.

擴充方法

GetMethodInfo(Delegate)

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

適用於

另請參閱