当ThreadPool.QueueUserWorkItem返回falseThreadPool、QueueUserWorkItem、false

2023-09-04 00:57:16 作者:今日份的xx

在MSDN指出该方法返回

The MSDN states that the method returns

true,如果该方法成功地   排队; NotSupportedException异常是   如果抛出的工作项目不排队。

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?

推荐答案

在查看源$ C ​​$ C的反射,似乎在code,可以返回假的唯一部件就是调用如下:

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);