Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When ThreadPool.QueueUserWorkItem returns false

The MSDN states that the method returns

true if the method is successfully queued; NotSupportedException is thrown if the work item is not queued.

For testing purposes how to get the method to return false? Or it is just a "suboptimal" class design?

like image 866
Michael Damatov Avatar asked Sep 29 '08 21:09

Michael Damatov


3 Answers

In looking at the source code in Reflector, it seems the only part of the code that could return "false" is a call to the following:

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool AdjustThreadsInPool(uint QueueLength);
like image 194
herbrandson Avatar answered Oct 20 '22 03:10

herbrandson


This is probably a case of "reserved for future use". You may want to treat it as failure, but it'll be hard to test.

I pretty much treat this method as a void/Sub.

like image 27
Bob King Avatar answered Oct 20 '22 03:10

Bob King


It is imaginable that the entire API (thread-pools) becomes obsolete, when the Task Parallel Library (TPL) arrives.

like image 26
Michael Damatov Avatar answered Oct 20 '22 03:10

Michael Damatov