views:

538

answers:

4

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?

A: 

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.

Bob King
+1  A: 

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

Michael Damatov
+3  A: 

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);
herbrandson
+1  A: 

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

Treat a return false in the same way that you treat a NotSupportedException.

To get it to return false, use a mock method or object.
You want to be testing your own code that you wrote, not the underlying windows code. I'm sure microsoft have plenty of their own tests already for that.

Orion Edwards
Exceptions were actually "invented" to prevent the practice "ignore the return value".
Michael Damatov