What is the exact purpose of WaitCallback delegate ?
WaitCallback callback = new WaitCallback(PrintMessage);
ThreadPool.QueueUserWorkItem(callback,"Hello");
static void PrintMessage(object obj)
{
Console.WriteLine(obj);
}
Can i mean "Wait" in the "TheadPool" until thread is availabe.Once it is available execute the target?
The WaitCallback in this case represents a pointer to a function that will be executed on a thread from the thread pool. If no thread is available it will wait until one gets freed.
From msdn
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.
Queue your task for execution by passing the WaitCallback delegate to ThreadPool..::.QueueUserWorkItem. Your callback method executes when a thread pool thread becomes available.
System.Threading.WaitCallBack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With