WaitCallback represents a callback method that you want to execute on a ThreadPool thread. Create the delegate by passing your callback method to the WaitCallback constructor. Your method must have the signature shown here.
Queue your task for execution by passing the WaitCallback delegate to ThreadPool..::.QueueUserWorkItem. Your callback method executes when a thread pool thread becomes available.
vb#
Note: |
|---|
Visual Basic users can omit the
WaitCallback constructor, and simply use the AddressOf operator when passing the callback method to QueueUserWorkItem. Visual Basic automatically calls the correct delegate constructor.
|
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.