Newly created threads using Task.Factory.StartNew starts very slowly Newly created threads using Task.Factory.StartNew starts very slowly multithreading multithreading

Newly created threads using Task.Factory.StartNew starts very slowly


Found out that the thread pool can be unwilling to start more than one new thread every 500 msec when the number of thread pool threads used are over a specific value. However increasing MinThreads using ThreadPool.SetMinThreads - even though it is not recommended - to 100 enables me to create 100 threads without the 500 msec delay.

Here's what helped me:

Edit:

Here's what I ended doing in App.xaml.cs (in the constructor):

// Get thread pool informationint workerThreadsMin, completionPortThreadsMin;ThreadPool.GetMinThreads(out workerThreadsMin, out completionPortThreadsMin);int workerThreadsMax, completionPortThreadsMax;ThreadPool.GetMaxThreads(out workerThreadsMax, out completionPortThreadsMax);// Adjust min threadsThreadPool.SetMinThreads(workerThreadsMax, completionPortThreadsMin);