Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Force Tasks to Start?

I have a program that scans a network, it does so by using a lot of tasks (and parallel foreaches) that wait for data to return from the network. The problem is that although I know that these tasks barely use any CPU processing, the CLR doesn't and it insists to start off very slowly (especially since this is running on a two core CPU).

How can I force the CLR to start more tasks at the same time? Currently the program is waiting a lot, how can I make it open more connections at the same time?

like image 977
Ziv Avatar asked Dec 04 '25 17:12

Ziv


1 Answers

You can either use async IO which does not require the TPL to start new threads, or you can start threads manually, or you can use ThreadPool.SetMinThreads. Don't use the last solution though because this is a process-wide setting. Don't pick a global solution for a local problem.

like image 95
usr Avatar answered Dec 06 '25 07:12

usr