I'm working on ASP .NET Core project, where I have classes managing a pool of worker threads for task execution, and I'm using the .NET thread pool to handle and execute tasks for processing incoming HTTP requests.
ThreadPool.SetMinThreads(workerThreads: 4, completionPortThreads: 4);
ThreadPool.SetMaxThreads(workerThreads: 70, completionPortThreads: 70);
My question is : Are there any limitations on the values that can be set for ThreadPool.SetMinThreads
and ThreadPool.SetMaxThreads
in an ASP.NET Core project?
Are there any limitations on the values that can be set for
ThreadPool.SetMinThreads
andThreadPool.SetMaxThreads
in an ASP.NET Core project?
Yes. According to the documentation of the first method:
If you specify a negative number or a number larger than the maximum number of active thread pool threads (obtained using
GetMaxThreads
),SetMinThreads
returnsfalse
and does not change either of the minimum values.
And according to the documentation of the second method:
The thread pool may have upper limits for the maximum thread counts (such as
short.MaxValue
, depending on the implementation). The argument values are capped to the upper limit, so even when the method returns true, the actual maximum thread counts may be lower than requested.