I'm using ThreadPool.QueueUserWorkItem()
. From MSDN I see that it can return FALSE if queuing failed. How am I supposed to react then? Wait a bit and try to queue again, hoping that a thread from th pool will be available then?
QueueUserWorkItem(WaitCallback, Object) Queues a method for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available.
After using threading namespace we need to call threadpool class, using threadpool object we need to call method i.e. "QueueUserWorkItem" - which Queues function for an execution and a function executes when a thread becomes available from thread pool. ThreadPool.
That's game over. Tell your user what happened and terminate your app.
It is unlikely to return false (See here: When ThreadPool.QueueUserWorkItem returns false). If it does - treat it as a failure and do not keep retrying.
Normally you would get a NotSupportedException
.
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