What would be the appropriate way to setup the ThreadPool in C#?
ThreadPool.SetMaxThreads(int workerThreads, int completionPortThreads)
I want the number of threads to equal the number of processor cores, but I’m not sure about the async I/O threads (the second parameter).
Can I simply say something like ThreadPool.SetMaxThreads(Environment.ProcessorCount, 0) so that the O/S deduces the second parameter itself?
The max completion port threads is used by asynchronous tasks, such as
Socket.Begin*orSocket.*Asyncand other IO-related tasks. I would recommend that if you change the worker threads, then you should just check what is the current max number of completion threads prior to changing the values:I think that by default the maximum number of completion threads is 1000, but that may vary from machine to machine. Just to be safe, use the value that you obtain from the
GetMaxThreadsfunction.