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

In a WPF / C # application that uses about 50-200 short live workflows created using Task.Factory.StartNew , it takes 1 to 10 seconds before the just created thread starts.

What is the reason for starting this very slow stream?

Update: Delay is 500ms

+7
multithreading c # task-parallel-library
source share
1 answer

It turned out that the thread pool might not want to start more than one new thread every 500 ms when the number of thread threads in a thread exceeds a certain value. However, increasing MinThreads with ThreadPool.SetMinThreads - even if it is not recommended - to 100 allows me to create 100 threads without a 500 ms delay.

Here is what helped me:

Edit:

Here is what I ended up in App.xaml.cs (in the constructor):

 // Get thread pool information int workerThreadsMin, completionPortThreadsMin; ThreadPool.GetMinThreads(out workerThreadsMin, out completionPortThreadsMin); int workerThreadsMax, completionPortThreadsMax; ThreadPool.GetMaxThreads(out workerThreadsMax, out completionPortThreadsMax); // Adjust min threads ThreadPool.SetMinThreads(workerThreadsMax, completionPortThreadsMin); 
+10
source share

All Articles