Lifecycle of a Thread Request
When the.NET framework receives a call method request, it generates a new thread object, allocates memory for it, and then begins task execution. When the task is completed, the garbage collector destroys the thread object to release memory space.
What is the use of Thread pooling?
For each request that comes in a multithread application, memory is allocated each time a new thread object is generated, which results in memory load that may slow down your application. Hence, the need for pooling.
Thread pool in C#
In C#, thread pooling is defined as a collection of threads and designed to perform background tasks. When a thread completes a task, it is added to the queue, which contains all the threads that are currently waiting. This is done to allow reuse threads.
Namespace used for Thread pooling in C#
To implement thread pooling, use threading namespace.
The ThreadPool.QueueUserWorkItem that is taken by Waitcallback method, (overloaded method) represents a callback function that will be invoked by a thread pool.
Calling ThreadPool class