System.Threading is the namespace where all thread-related C# classes reside. The following tables list the classes (Table 16.1), delegates (Table 16.2), and enumerations (Table 16.3) of this namespace.
The following sections discuss the key classes, delegates, and enumerations in the namespace.
Table 16.1. System.Threading Classes
Class
Description
AutoResetEvent
Notifies one or more waiting threads that an event has occurred. This class cannot be inherited.
Interlocked
Provides atomic operations for variables that are shared by multiple threads.
ManualResetEvent
Occurs when one or more waiting threads are notified that an event has occurred. This class cannot be inherited.
Monitor
Provides a mechanism that synchronizes access to objects.
Mutex
A synchronization primitive that can also be used for interprocess synchronization.
ReaderWriterLock
Defines the lock that implements single-writer and multiple-reader semantics.
RegisteredWaitHandle
Represents a handle that has been registered when calling RegisterWaitForSingleObject. This class cannot be inherited.
SynchronizationLockException
The exception that is thrown when a synchronized method is invoked from an unsynchronized block of code.
Thread
Creates and controls a thread, sets its priority, and gets its status.
ThreadAbortException
The exception that is thrown when a call is made to the Abort method. This class cannot be inherited.
ThreadExceptionEventArgs
Provides data for the ThreadException event.
ThreadInterruptedException
The exception that is thrown when a thread is interrupted while it is in a waiting state.
ThreadPool
Provides a pool of threads that can be used to post work items, process asynchronous I/O, wait on behalf of other threads, and process timers.
ThreadStateException
The exception that is thrown when a thread is in an invalid ThreadState for the method call.
Timeout
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Timer
Provides a mechanism for executing methods at specified intervals. This class cannot be inherited.
WaitHandle
Encapsulates operating-system-specific objects that wait for exclusive access to shared resources.
Table 16.2. System.Threading Delegates
Delegate
Description
IOCompletionCallback
Receives the error code, number of bytes, and overlapped value type when an I/O operation completes on the thread pool.
ThreadExceptionEventHandler
Represents the method that will handle the ThreadException event of an application.
ThreadStart
Represents the method that will handle the Start event of the Thread class.
TimerCallback
Represents the method that will handle the state of a Timer.
WaitCallback
Defines the callback method for thread pool user work items. That method must match this delegate.
WaitOrTimerCallback
Receives a Boolean parameter that determines whether the handle was signaled or the WaitHandle timed out.