Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check the Number of threads available in ThreadPool at any time

Where and how to check through code number of threads available in threadpool.

What i want is: For example if no of threads in threadpool are 10 then at any given time I should not be using say more than 3 threads. Once an existing thread gets free, I should start a new task, keeping max count 3.

like image 605
dotnetavalanche Avatar asked Jun 13 '16 10:06

dotnetavalanche


People also ask

How many maximum threads can be created using a ThreadPool?

ThreadPool will create maximum of 10 threads to process 10 requests at a time. After process completion of any single Thread, ThreadPool will internally allocate the 11th request to this Thread and will keep on doing the same to all the remaining requests.

What is the difference between thread and ThreadPool?

A thread pool is - as the name suggests - a pool of worker threads which are always running. Those threads then normally take tasks from a list, execute them, then try to take the next task. If there's no task, the thread will wait.

How many thread can I run C#?

NET Thread Pool default numbers of threads: 1023 in Framework 4.0 (32-bit environment) 32767 in Framework 4.0 (64-bit environment)


Video Answer


1 Answers

ThreadPool.GetAvailableThreads will give you number of available threads. ThreadPool.GetMaxThreads will give you max number of threads. The difference will give you the number of active threads.

like image 50
kiran Avatar answered Sep 20 '22 01:09

kiran