mscorlib(4.0.0.0) API with additions
System.Threading Namespace Reference

Classes

class  AbandonedMutexException
 The exception that is thrown when one thread acquires a T:System.Threading.Mutex object that another thread has abandoned by exiting without releasing it. More...
 
struct  AsyncFlowControl
 Provides the functionality to restore the migration, or flow, of the execution context between threads. More...
 
class  AsyncLocal
 Represents ambient data that is local to a given asynchronous control flow, such as an asynchronous method. More...
 
struct  AsyncLocalValueChangedArgs
 The class that provides data change information to T:System.Threading.AsyncLocal`1 instances that register for change notifications. More...
 
class  AutoResetEvent
 Notifies a waiting thread that an event has occurred. This class cannot be inherited. More...
 
class  Barrier
 Enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases. More...
 
class  BarrierPostPhaseException
 The exception that is thrown when the post-phase action of a T:System.Threading.Barrier fails More...
 
struct  CancellationToken
 Propagates notification that operations should be canceled. More...
 
struct  CancellationTokenRegistration
 Represents a callback delegate that has been registered with a T:System.Threading.CancellationToken. More...
 
class  CancellationTokenSource
 Signals to a T:System.Threading.CancellationToken that it should be canceled. More...
 
class  CompressedStack
 Provides methods for setting and capturing the compressed stack on the current thread. This class cannot be inherited. More...
 
class  CountdownEvent
 Represents a synchronization primitive that is signaled when its count reaches zero. More...
 
class  EventWaitHandle
 Represents a thread synchronization event. More...
 
class  ExecutionContext
 Manages the execution context for the current thread. This class cannot be inherited. More...
 
class  HostExecutionContext
 Encapsulates and propagates the host execution context across threads. More...
 
class  HostExecutionContextManager
 Provides the functionality that allows a common language runtime host to participate in the flow, or migration, of the execution context. More...
 
class  Interlocked
 Provides atomic operations for variables that are shared by multiple threads. More...
 
class  LazyInitializer
 Provides lazy initialization routines. More...
 
struct  LockCookie
 Defines the lock that implements single-writer/multiple-reader semantics. This is a value type. More...
 
class  LockRecursionException
 The exception that is thrown when recursive entry into a lock is not compatible with the recursion policy for the lock. More...
 
class  ManualResetEvent
 Notifies one or more waiting threads that an event has occurred. This class cannot be inherited. More...
 
class  ManualResetEventSlim
 Provides a slimmed down version of T:System.Threading.ManualResetEvent. More...
 
class  Monitor
 Provides a mechanism that synchronizes access to objects. More...
 
class  Mutex
 A synchronization primitive that can also be used for interprocess synchronization. More...
 
struct  NativeOverlapped
 Provides an explicit layout that is visible from unmanaged code and that will have the same layout as the Win32 OVERLAPPED structure with additional reserved fields at the end. More...
 
class  Overlapped
 Provides a managed representation of a Win32 OVERLAPPED structure, including methods to transfer information from an T:System.Threading.Overlapped instance to a T:System.Threading.NativeOverlapped structure. More...
 
class  PreAllocatedOverlapped
 Represents pre-allocated state for native overlapped I/O operations. More...
 
class  ReaderWriterLock
 Defines a lock that supports single writers and multiple readers. More...
 
class  ReaderWriterLockSlim
 Represents a lock that is used to manage access to a resource, allowing multiple threads for reading or exclusive access for writing. More...
 
class  RegisteredWaitHandle
 Represents a handle that has been registered when calling M:System.Threading.ThreadPool.RegisterWaitForSingleObject(System.Threading.WaitHandle,System.Threading.WaitOrTimerCallback,System.Object,System.UInt32,System.Boolean). This class cannot be inherited. More...
 
class  Semaphore
 Limits the number of threads that can access a resource or pool of resources concurrently. More...
 
class  SemaphoreFullException
 The exception that is thrown when the Overload:System.Threading.Semaphore.Release method is called on a semaphore whose count is already at the maximum. More...
 
class  SemaphoreSlim
 Represents a lightweight alternative to T:System.Threading.Semaphore that limits the number of threads that can access a resource or pool of resources concurrently. More...
 
struct  SpinLock
 Provides a mutual exclusion lock primitive where a thread trying to acquire the lock waits in a loop repeatedly checking until the lock becomes available. More...
 
struct  SpinWait
 Provides support for spin-based waiting. More...
 
class  SynchronizationContext
 Provides the basic functionality for propagating a synchronization context in various synchronization models. More...
 
class  SynchronizationLockException
 The exception that is thrown when a method requires the caller to own the lock on a given Monitor, and the method is invoked by a caller that does not own that lock. More...
 
class  Thread
 Creates and controls a thread, sets its priority, and gets its status. More...
 
class  ThreadAbortException
 The exception that is thrown when a call is made to the M:System.Threading.Thread.Abort(System.Object) method. This class cannot be inherited. More...
 
class  ThreadExceptionEventArgs
 Provides data for the E:System.Windows.Forms.Application.ThreadException event. More...
 
class  ThreadInterruptedException
 The exception that is thrown when a T:System.Threading.Thread is interrupted while it is in a waiting state. More...
 
class  ThreadLocal
 Provides thread-local storage of data. More...
 
class  ThreadPool
 Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I/O, wait on behalf of other threads, and process timers. More...
 
class  ThreadPoolBoundHandle
 Represents an I/O handle that is bound to the system thread pool and enables low-level components to receive notifications for asynchronous I/O operations. More...
 
class  ThreadStartException
 The exception that is thrown when a failure occurs in a managed thread after the underlying operating system thread has been started, but before the thread is ready to execute user code. More...
 
class  ThreadStateException
 The exception that is thrown when a T:System.Threading.Thread is in an invalid P:System.Threading.Thread.ThreadState for the method call. More...
 
class  Timeout
 Contains constants that specify infinite time-out intervals. This class cannot be inherited. More...
 
class  Timer
 Provides a mechanism for executing a method on a thread pool thread at specified intervals. This class cannot be inherited.To browse the .NET Framework source code for this type, see the Reference Source. More...
 
class  Volatile
 Contains methods for performing volatile memory operations. More...
 
class  WaitHandle
 Encapsulates operating system–specific objects that wait for exclusive access to shared resources. More...
 
class  WaitHandleCannotBeOpenedException
 The exception that is thrown when an attempt is made to open a system mutex, semaphore, or event wait handle that does not exist. More...
 
class  WaitHandleExtensions
 Provides convenience methods to for working with a safe handle for a wait handle. More...
 

Enumerations

enum  ApartmentState { ApartmentState.STA, ApartmentState.MTA, ApartmentState.Unknown }
 Specifies the apartment state of a T:System.Threading.Thread. More...
 
enum  EventResetMode { EventResetMode.AutoReset, EventResetMode.ManualReset }
 Indicates whether an T:System.Threading.EventWaitHandle is reset automatically or manually after receiving a signal. More...
 
enum  LazyThreadSafetyMode { LazyThreadSafetyMode.None, LazyThreadSafetyMode.PublicationOnly, LazyThreadSafetyMode.ExecutionAndPublication }
 Specifies how a T:System.Lazy`1 instance synchronizes access among multiple threads. More...
 
enum  LockRecursionPolicy { LockRecursionPolicy.NoRecursion, LockRecursionPolicy.SupportsRecursion }
 Specifies whether a lock can be entered multiple times by the same thread. More...
 
enum  StackCrawlMark { LookForMe, LookForMyCaller, LookForMyCallersCaller, LookForThread }
 
enum  SynchronizationContextProperties { None = 0x0, RequireWaitNotification = 0x1 }
 
enum  ThreadPriority {
  ThreadPriority.Lowest, ThreadPriority.BelowNormal, ThreadPriority.Normal, ThreadPriority.AboveNormal,
  ThreadPriority.Highest
}
 Specifies the scheduling priority of a T:System.Threading.Thread. More...
 
enum  ThreadState {
  ThreadState.Running = 0x0, ThreadState.StopRequested = 0x1, ThreadState.SuspendRequested = 0x2, ThreadState.Background = 0x4,
  ThreadState.Unstarted = 0x8, ThreadState.Stopped = 0x10, ThreadState.WaitSleepJoin = 0x20, ThreadState.Suspended = 0x40,
  ThreadState.AbortRequested = 0x80, ThreadState.Aborted = 0x100
}
 Specifies the execution states of a T:System.Threading.Thread. More...
 

Functions

delegate void ContextCallback (object state)
 Represents a method to be called within a new context. More...
 
internal delegate object InternalCrossContextDelegate (object[] args)
 
unsafe delegate void IOCompletionCallback (uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP)
 Receives the error code, number of bytes, and overlapped value type when an I/O operation completes on the thread pool. More...
 
delegate void ParameterizedThreadStart (object obj)
 Represents the method that executes on a T:System.Threading.Thread. More...
 
delegate void SendOrPostCallback (object state)
 Represents a method to be called when a message is to be dispatched to a synchronization context. More...
 
delegate void ThreadExceptionEventHandler (object sender, ThreadExceptionEventArgs e)
 Represents the method that will handle the E:System.Windows.Forms.Application.ThreadException event of an T:System.Windows.Forms.Application. More...
 
delegate void ThreadStart ()
 Represents the method that executes on a T:System.Threading.Thread. More...
 
delegate void TimerCallback (object state)
 Represents the method that handles calls from a T:System.Threading.Timer. More...
 
delegate void WaitCallback (object state)
 Represents a callback method to be executed by a thread pool thread. More...
 
delegate void WaitOrTimerCallback (object state, bool timedOut)
 Represents a method to be called when a T:System.Threading.WaitHandle is signaled or times out. More...
 

Enumeration Type Documentation

◆ ApartmentState

Specifies the apartment state of a T:System.Threading.Thread.

Enumerator
STA 

The T:System.Threading.Thread will create and enter a single-threaded apartment.

MTA 

The T:System.Threading.Thread will create and enter a multithreaded apartment.

Unknown 

The P:System.Threading.Thread.ApartmentState property has not been set.

Definition at line 8 of file ApartmentState.cs.

◆ EventResetMode

Indicates whether an T:System.Threading.EventWaitHandle is reset automatically or manually after receiving a signal.

Enumerator
AutoReset 

When signaled, the T:System.Threading.EventWaitHandle resets automatically after releasing a single thread. If no threads are waiting, the T:System.Threading.EventWaitHandle remains signaled until a thread blocks, and resets after releasing the thread.

ManualReset 

When signaled, the T:System.Threading.EventWaitHandle releases all waiting threads and remains signaled until it is manually reset.

Definition at line 8 of file EventResetMode.cs.

◆ LazyThreadSafetyMode

Specifies how a T:System.Lazy`1 instance synchronizes access among multiple threads.

Enumerator
None 

The T:System.Lazy`1 instance is not thread safe; if the instance is accessed from multiple threads, its behavior is undefined. Use this mode only when high performance is crucial and the T:System.Lazy`1 instance is guaranteed never to be initialized from more than one thread. If you use a T:System.Lazy`1 constructor that specifies an initialization method (valueFactory parameter), and if that initialization method throws an exception (or fails to handle an exception) the first time you call the P:System.Lazy`1.Value property, then the exception is cached and thrown again on subsequent calls to the P:System.Lazy`1.Value property. If you use a T:System.Lazy`1 constructor that does not specify an initialization method, exceptions that are thrown by the default constructor for T are not cached. In that case, a subsequent call to the P:System.Lazy`1.Value property might successfully initialize the T:System.Lazy`1 instance. If the initialization method recursively accesses the P:System.Lazy`1.Value property of the T:System.Lazy`1 instance, an T:System.InvalidOperationException is thrown.

PublicationOnly 

When multiple threads try to initialize a T:System.Lazy`1 instance simultaneously, all threads are allowed to run the initialization method (or the default constructor, if there is no initialization method). The first thread to complete initialization sets the value of the T:System.Lazy`1 instance. That value is returned to any other threads that were simultaneously running the initialization method, unless the initialization method throws exceptions on those threads. Any instances of T that were created by the competing threads are discarded. If the initialization method throws an exception on any thread, the exception is propagated out of the P:System.Lazy`1.Value property on that thread. The exception is not cached. The value of the P:System.Lazy`1.IsValueCreated property remains false, and subsequent calls to the P:System.Lazy`1.Value property, either by the thread where the exception was thrown or by other threads, cause the initialization method to run again. If the initialization method recursively accesses the P:System.Lazy`1.Value property of the T:System.Lazy`1 instance, no exception is thrown.

ExecutionAndPublication 

Locks are used to ensure that only a single thread can initialize a T:System.Lazy`1 instance in a thread-safe manner. If the initialization method (or the default constructor, if there is no initialization method) uses locks internally, deadlocks can occur. If you use a T:System.Lazy`1 constructor that specifies an initialization method (valueFactory parameter), and if that initialization method throws an exception (or fails to handle an exception) the first time you call the P:System.Lazy`1.Value property, then the exception is cached and thrown again on subsequent calls to the P:System.Lazy`1.Value property. If you use a T:System.Lazy`1 constructor that does not specify an initialization method, exceptions that are thrown by the default constructor for T are not cached. In that case, a subsequent call to the P:System.Lazy`1.Value property might successfully initialize the T:System.Lazy`1 instance. If the initialization method recursively accesses the P:System.Lazy`1.Value property of the T:System.Lazy`1 instance, an T:System.InvalidOperationException is thrown.

Definition at line 5 of file LazyThreadSafetyMode.cs.

◆ LockRecursionPolicy

Specifies whether a lock can be entered multiple times by the same thread.

Enumerator
NoRecursion 

If a thread tries to enter a lock recursively, an exception is thrown. Some classes may allow certain recursions when this setting is in effect.

SupportsRecursion 

A thread can enter a lock recursively. Some classes may restrict this capability.

Definition at line 5 of file LockRecursionPolicy.cs.

◆ ThreadPriority

Specifies the scheduling priority of a T:System.Threading.Thread.

Enumerator
Lowest 

The T:System.Threading.Thread can be scheduled after threads with any other priority.

BelowNormal 

The T:System.Threading.Thread can be scheduled after threads with Normal priority and before those with Lowest priority.

Normal 

The T:System.Threading.Thread can be scheduled after threads with AboveNormal priority and before those with BelowNormal priority. Threads have Normal priority by default.

AboveNormal 

The T:System.Threading.Thread can be scheduled after threads with Highest priority and before those with Normal priority.

Highest 

The T:System.Threading.Thread can be scheduled before threads with any other priority.

Definition at line 8 of file ThreadPriority.cs.

◆ ThreadState

Specifies the execution states of a T:System.Threading.Thread.

Enumerator
Running 

The thread has been started, it is not blocked, and there is no pending T:System.Threading.ThreadAbortException.

StopRequested 

The thread is being requested to stop. This is for internal use only.

SuspendRequested 

The thread is being requested to suspend.

Background 

The thread is being executed as a background thread, as opposed to a foreground thread. This state is controlled by setting the P:System.Threading.Thread.IsBackground property.

Unstarted 

The M:System.Threading.Thread.Start method has not been invoked on the thread.

Stopped 

The thread has stopped.

WaitSleepJoin 

The thread is blocked. This could be the result of calling M:System.Threading.Thread.Sleep(System.Int32) or M:System.Threading.Thread.Join, of requesting a lock — for example, by calling M:System.Threading.Monitor.Enter(System.Object) or M:System.Threading.Monitor.Wait(System.Object,System.Int32,System.Boolean) — or of waiting on a thread synchronization object such as T:System.Threading.ManualResetEvent.

Suspended 

The thread has been suspended.

AbortRequested 

The M:System.Threading.Thread.Abort(System.Object) method has been invoked on the thread, but the thread has not yet received the pending T:System.Threading.ThreadAbortException that will attempt to terminate it.

Aborted 

The thread state includes F:System.Threading.ThreadState.AbortRequested and the thread is now dead, but its state has not yet changed to F:System.Threading.ThreadState.Stopped.

Definition at line 9 of file ThreadState.cs.

Function Documentation

◆ ContextCallback()

delegate void System.Threading.ContextCallback ( object  state)

Represents a method to be called within a new context.

Parameters
stateAn object containing information to be used by the callback method each time it executes.

◆ IOCompletionCallback()

unsafe delegate void System.Threading.IOCompletionCallback ( uint  errorCode,
uint  numBytes,
NativeOverlapped pOVERLAP 
)

Receives the error code, number of bytes, and overlapped value type when an I/O operation completes on the thread pool.

Parameters
errorCodeThe error code.
numBytesThe number of bytes that are transferred.
pOVERLAPA T:System.Threading.NativeOverlapped representing an unmanaged pointer to the native overlapped value type.

◆ ParameterizedThreadStart()

delegate void System.Threading.ParameterizedThreadStart ( object  obj)

Represents the method that executes on a T:System.Threading.Thread.

Parameters
objAn object that contains data for the thread procedure.

◆ SendOrPostCallback()

delegate void System.Threading.SendOrPostCallback ( object  state)

Represents a method to be called when a message is to be dispatched to a synchronization context.

Parameters
stateThe object passed to the delegate.

◆ ThreadExceptionEventHandler()

delegate void System.Threading.ThreadExceptionEventHandler ( object  sender,
ThreadExceptionEventArgs  e 
)

Represents the method that will handle the E:System.Windows.Forms.Application.ThreadException event of an T:System.Windows.Forms.Application.

Parameters
senderThe source of the event.
eA T:System.Threading.ThreadExceptionEventArgs that contains the event data.

◆ ThreadStart()

delegate void System.Threading.ThreadStart ( )

Represents the method that executes on a T:System.Threading.Thread.

◆ TimerCallback()

delegate void System.Threading.TimerCallback ( object  state)

Represents the method that handles calls from a T:System.Threading.Timer.

Parameters
stateAn object containing application-specific information relevant to the method invoked by this delegate, or null.

◆ WaitCallback()

delegate void System.Threading.WaitCallback ( object  state)

Represents a callback method to be executed by a thread pool thread.

Parameters
stateAn object containing information to be used by the callback method.

◆ WaitOrTimerCallback()

delegate void System.Threading.WaitOrTimerCallback ( object  state,
bool  timedOut 
)

Represents a method to be called when a T:System.Threading.WaitHandle is signaled or times out.

Parameters
stateAn object containing information to be used by the callback method each time it executes.
timedOuttrue if the T:System.Threading.WaitHandle timed out; false if it was signaled.