WaitCallback 委托

定义

表示要由线程池线程执行的回调方法。Represents a callback method to be executed by a thread pool thread.

public delegate void WaitCallback(System::Object ^ state);
[System.Runtime.InteropServices.ComVisible(true)]
public delegate void WaitCallback(object state);
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 表示要在 ThreadPool 线程上执行的回调方法。WaitCallback represents a callback method that you want to execute on a ThreadPool thread. 通过向 WaitCallback 构造函数传递回调方法来创建委托。Create the delegate by passing your callback method to the WaitCallback constructor. 你的方法必须具有此处显示的签名。Your method must have the signature shown here.

通过将 WaitCallback 委托传递给 ThreadPool.QueueUserWorkItem来将方法排队以便执行。Queue 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 构造函数,只需在将回调方法传递给 QueueUserWorkItem时使用 AddressOf 运算符。Visual 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.

有关线程池的详细信息,请参阅托管线程池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.

适用于

另请参阅