ThreadPool class is used to manage a set of readily
available threads to be used by a process. We can use ThreadPool class for
creating threads when we require large number of short living threads. A short
living thread is a thread that is created to perform a single task and then
terminated.We can use ThreadPool class when it is not necessary to have full
control over each individual threads.
Note: There is a limit of 25 threads in a thread pool. That means if you
start 50 threads then only 25 threads is active at a time. As soon as a thread
finishes another thread is active from thread pool.
Avoiding uses of ThreadPool class when following situation raise
Requires a foreground thread.
Requires a thread to have a particular priority.
Have task that can block threads for long period
of time. The thread pool has a maximum number of threads, so a large number of
threads from the thread pool being blocked might prevent task from starting.
Need to have stable identity associated with
Need to place threads into a single threaded
Implementation of ThreadPool class
method of ThreadPool claas
//to send Thread in
ThreadPool and pass object of
This method is passed to WaitCallback delegate.
This method is used to print numbers from 1 to 50.
Main thread exists in two case either time fiven in main sleep
method over of number is printed from 1 to 50.
from thread pool. I will count from 1 to 50");
for (int i
= 1; i <= 50; i++)
Execute above program to see the output.