Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How am I supposed to react if ThreadPool.QueueUserWorkItem() returns FALSE?

Tags:

c#

.net

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?

like image 635
Krumelur Avatar asked Apr 14 '11 10:04

Krumelur


People also ask

What is the use of Threadpool QueueUserWorkItem method?

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.

How do you call a function using Threadpool in C#?

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.


2 Answers

That's game over. Tell your user what happened and terminate your app.

like image 165
David Heffernan Avatar answered Oct 22 '22 16:10

David Heffernan


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.

like image 22
David Neale Avatar answered Oct 22 '22 17:10

David Neale