Represents a callback method to be executed by a thread pool thread.
Assembly: mscorlib (in mscorlib.dll)
ThreadPool thread. Create the delegate by passing your callback method to the constructor. Your method must have the signature shown here.represents a callback method that you want to execute on a
Queue your task for execution by passing the ThreadPool.QueueUserWorkItem. Your callback method executes when a thread pool thread becomes available.delegate to
Visual Basic users can omit the QueueUserWorkItem. Visual Basic automatically calls the correct delegate constructor.constructor, and simply use the AddressOf operator when passing the callback method to
If you want to pass information to your callback method, create an object that contains the necessary information and pass it to QueueUserWorkItem when you queue your task for execution. Each time your callback method executes, the state parameter contains this object.
For more information about using callbacks to synchronize thread pool threads, see The Managed Thread Pool.
This section contains two examples. The first example demonstrates how you can queue a simple task for execution by the thread pool.
The second example demonstrates how you can queue a task and pass information to it.
This example shows how to use the ThreadPool.QueueUserWorkItem(WaitCallback) method overload to queue a task, which is represented by a that wraps the ThreadProc method, to execute when a thread becomes available. No task information is supplied with this overload. Therefore, the information that is available to the ThreadProc method is limited to the object the method belongs to.delegate to queue a task for execution by the thread pool. The code example uses the
This example shows how to create an object that contains task information. It also demonstrates how to pass that object to a task that is queued for execution by the thread pool.
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0