Number of C # Threads

What would be the appropriate installation method ThreadPoolin C#?

ThreadPool.SetMaxThreads(int workerThreads, int completionPortThreads)

I want the number of threads to match the number of processor cores, but I'm not sure about asynchronous I / O threads (second parameter).

Can you just say something like ThreadPool.SetMaxThreads(Environment.ProcessorCount, 0)O / S output the second parameter?

+5
source share
1 answer

, Socket.Begin* Socket.*Async , IO. , , , :

int maxWorkerThreads;
int maxCompletionThreads;

// Get the maximum number of completion threads
ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionThreads);

// Set the new max worker threads, but keep the old max completion threads
ThreadPool.SetMaxThreads(someDifferentValue, maxCompletionThreads);

, 1000, . , , GetMaxThreads.

+6

All Articles