The System.Threading Namespace
The System.Threading namespace provides classes and interfaces that enables multithreaded programming. This namespace includes a ThreadPool class that manages groups of threads, a Timer class that enables a delegate to be called after a specified amount of time, and a Mutex Class for synchronizing mutually-exclusive threads. System.Threading also provides classes for thread scheduling, wait notification, and deadlock resolution.
Some of the important classes in System.Threading namespace is discussed below.
Thread - Represents threads that execute within the runtime, to create and control threads.
ThreadPool - Posts work items to the thread pool. Queue work items for execution on the first available thread from the thread pool. One OS thread pool per process. Efficient use of thread resources.
Timeout - Contains timeout values for the system
Times - Specifies a delegate to be called at a specified time. The wait operation is performed by a thread in the thread pool.
Monitor - Provides the synchronization of threading objects using locks and wait/signals.
Mutex - A synchronization primitive that can also be used for interprocess synchronization. Wait can be used to request ownership of the mutex. The state of the mutex is signaled if no thread owns it.
The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its executions. It must release the mutex as many times ti release ownership. If a thread terminates normally while owning a mutex, the state of the mutex is set to signaled and the next waiting thread gets ownership.
Life Cycle Methods
Starting a Thread
The thread class of System.Threading Namespace represents a thread object. By using class object, we can create new threads, delete, pause and resume threads. The thread class creates a new thread and Thread.Start method starts a thread.
Join the conversation! Your thoughts help the community grow.