mscorlib(4.0.0.0) API with additions
System.Threading.Thread Class Reference

Creates and controls a thread, sets its priority, and gets its status. More...

Inheritance diagram for System.Threading.Thread:
[legend]
Collaboration diagram for System.Threading.Thread:
[legend]

Public Member Functions

 Thread (ThreadStart start)
 Initializes a new instance of the T:System.Threading.Thread class. More...
 
 Thread (ThreadStart start, int maxStackSize)
 Initializes a new instance of the T:System.Threading.Thread class, specifying the maximum stack size for the thread. More...
 
 Thread (ParameterizedThreadStart start)
 Initializes a new instance of the T:System.Threading.Thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started. More...
 
 Thread (ParameterizedThreadStart start, int maxStackSize)
 Initializes a new instance of the T:System.Threading.Thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started and specifying the maximum stack size for the thread. More...
 
override int GetHashCode ()
 Returns a hash code for the current thread. More...
 
void Start ()
 Causes the operating system to change the state of the current instance to F:System.Threading.ThreadState.Running. More...
 
void Start (object parameter)
 Causes the operating system to change the state of the current instance to F:System.Threading.ThreadState.Running, and optionally supplies an object containing data to be used by the method the thread executes. More...
 
void SetCompressedStack (CompressedStack stack)
 Applies a captured T:System.Threading.CompressedStack to the current thread. More...
 
CompressedStack GetCompressedStack ()
 Returns a T:System.Threading.CompressedStack object that can be used to capture the stack for the current thread. More...
 
void Abort (object stateInfo)
 Raises a T:System.Threading.ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread while also providing exception information about the thread termination. Calling this method usually terminates the thread. More...
 
void Abort ()
 Raises a T:System.Threading.ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread. Calling this method usually terminates the thread. More...
 
void Suspend ()
 Either suspends the thread, or if the thread is already suspended, has no effect. More...
 
void Resume ()
 Resumes a thread that has been suspended. More...
 
void Interrupt ()
 Interrupts a thread that is in the WaitSleepJoin thread state. More...
 
void Join ()
 Blocks the calling thread until the thread represented by this instance terminates, while continuing to perform standard COM and SendMessage pumping. More...
 
bool Join (int millisecondsTimeout)
 Blocks the calling thread until the thread represented by this instance terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping. More...
 
bool Join (TimeSpan timeout)
 Blocks the calling thread until the thread represented by this instance terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping. More...
 
void DisableComObjectEagerCleanup ()
 Turns off automatic cleanup of runtime callable wrappers (RCW) for the current thread. More...
 
ApartmentState GetApartmentState ()
 Returns an T:System.Threading.ApartmentState value indicating the apartment state. More...
 
bool TrySetApartmentState (ApartmentState state)
 Sets the apartment state of a thread before it is started. More...
 
void SetApartmentState (ApartmentState state)
 Sets the apartment state of a thread before it is started. More...
 
static void BeginCriticalRegion ()
 Notifies a host that execution is about to enter a region of code in which the effects of a thread abort or unhandled exception might jeopardize other tasks in the application domain. More...
 
static void EndCriticalRegion ()
 Notifies a host that execution is about to enter a region of code in which the effects of a thread abort or unhandled exception are limited to the current task. More...
 
static void BeginThreadAffinity ()
 Notifies a host that managed code is about to execute instructions that depend on the identity of the current physical operating system thread. More...
 
static void EndThreadAffinity ()
 Notifies a host that managed code has finished executing instructions that depend on the identity of the current physical operating system thread. More...
 
static void MemoryBarrier ()
 Synchronizes memory access as follows: The processor executing the current thread cannot reorder instructions in such a way that memory accesses prior to the call to M:System.Threading.Thread.MemoryBarrier execute after memory accesses that follow the call to M:System.Threading.Thread.MemoryBarrier. More...
 

Static Public Member Functions

static void ResetAbort ()
 Cancels an M:System.Threading.Thread.Abort(System.Object) requested for the current thread. More...
 
static void Sleep (int millisecondsTimeout)
 Suspends the current thread for the specified number of milliseconds. More...
 
static void Sleep (TimeSpan timeout)
 Suspends the current thread for the specified amount of time. More...
 
static void SpinWait (int iterations)
 Causes a thread to wait the number of times defined by the iterations parameter. More...
 
static bool Yield ()
 Causes the calling thread to yield execution to another thread that is ready to run on the current processor. The operating system selects the thread to yield to. More...
 
static LocalDataStoreSlot AllocateDataSlot ()
 Allocates an unnamed data slot on all the threads. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead. More...
 
static LocalDataStoreSlot AllocateNamedDataSlot (string name)
 Allocates a named data slot on all threads. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead. More...
 
static LocalDataStoreSlot GetNamedDataSlot (string name)
 Looks up a named data slot. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead. More...
 
static void FreeNamedDataSlot (string name)
 Eliminates the association between a name and a slot, for all threads in the process. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead. More...
 
static object GetData (LocalDataStoreSlot slot)
 Retrieves the value from the specified slot on the current thread, within the current thread's current domain. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead. More...
 
static void SetData (LocalDataStoreSlot slot, object data)
 Sets the data in the specified slot on the currently running thread, for that thread's current domain. For better performance, use fields marked with the T:System.ThreadStaticAttribute attribute instead. More...
 
static AppDomain GetDomain ()
 Returns the current domain in which the current thread is running. More...
 
static int GetDomainID ()
 Returns a unique application domain identifier. More...
 
static byte VolatileRead (ref byte address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static short VolatileRead (ref short address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static int VolatileRead (ref int address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static long VolatileRead (ref long address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static sbyte VolatileRead (ref sbyte address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static ushort VolatileRead (ref ushort address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static uint VolatileRead (ref uint address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static IntPtr VolatileRead (ref IntPtr address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static UIntPtr VolatileRead (ref UIntPtr address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static ulong VolatileRead (ref ulong address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static float VolatileRead (ref float address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static double VolatileRead (ref double address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static object VolatileRead (ref object address)
 Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache. More...
 
static void VolatileWrite (ref byte address, byte value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref short address, short value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref int address, int value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref long address, long value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref sbyte address, sbyte value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref ushort address, ushort value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref uint address, uint value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref IntPtr address, IntPtr value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref UIntPtr address, UIntPtr value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref ulong address, ulong value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref float address, float value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref double address, double value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 
static void VolatileWrite (ref object address, object value)
 Writes a value to a field immediately, so that the value is visible to all processors in the computer. More...
 

Properties

int ManagedThreadId [get]
 Gets a unique identifier for the current managed thread. More...
 
ExecutionContext ExecutionContext [get]
 Gets an T:System.Threading.ExecutionContext object that contains information about the various contexts of the current thread. More...
 
ThreadPriority Priority [get, set]
 Gets or sets a value indicating the scheduling priority of a thread. More...
 
bool IsAlive [get]
 Gets a value indicating the execution status of the current thread. More...
 
bool IsThreadPoolThread [get]
 Gets a value indicating whether or not a thread belongs to the managed thread pool. More...
 
static Thread CurrentThread [get]
 Gets the currently running thread. More...
 
bool IsBackground [get, set]
 Gets or sets a value indicating whether or not a thread is a background thread. More...
 
ThreadState ThreadState [get]
 Gets a value containing the states of the current thread. More...
 
ApartmentState ApartmentState [get, set]
 Gets or sets the apartment state of this thread. More...
 
CultureInfo?? CurrentUICulture [get, set]
 Gets or sets the current culture used by the Resource Manager to look up culture-specific resources at run time. More...
 
CultureInfo?? CurrentCulture [get, set]
 Gets or sets the culture for the current thread. More...
 
static Context CurrentContext [get]
 Gets the current context in which the thread is executing. More...
 
static IPrincipal CurrentPrincipal [get, set]
 Gets or sets the thread's current principal (for role-based security). More...
 
string??? Name [get, set]
 Gets or sets the name of the thread. More...
 

Additional Inherited Members

- Protected Member Functions inherited from System.Runtime.ConstrainedExecution.CriticalFinalizerObject
 CriticalFinalizerObject ()
 Initializes a new instance of the T:System.Runtime.ConstrainedExecution.CriticalFinalizerObject class. More...
 

Detailed Description

Creates and controls a thread, sets its priority, and gets its status.

Definition at line 18 of file Thread.cs.

Constructor & Destructor Documentation

◆ Thread() [1/4]

System.Threading.Thread.Thread ( ThreadStart  start)

Initializes a new instance of the T:System.Threading.Thread class.

Parameters
startA T:System.Threading.ThreadStart delegate that represents the methods to be invoked when this thread begins executing.
Exceptions
T:System.ArgumentNullExceptionThe start parameter is null.

Definition at line 392 of file Thread.cs.

◆ Thread() [2/4]

System.Threading.Thread.Thread ( ThreadStart  start,
int  maxStackSize 
)

Initializes a new instance of the T:System.Threading.Thread class, specifying the maximum stack size for the thread.

Parameters
startA T:System.Threading.ThreadStart delegate that represents the methods to be invoked when this thread begins executing.
maxStackSizeThe maximum stack size, in bytes, to be used by the thread, or 0 to use the default maximum stack size specified in the header for the executable.Important   For partially trusted code, maxStackSize is ignored if it is greater than the default stack size. No exception is thrown.
Exceptions
T:System.ArgumentNullExceptionstart is null.
T:System.ArgumentOutOfRangeExceptionmaxStackSize is less than zero.

Definition at line 409 of file Thread.cs.

◆ Thread() [3/4]

System.Threading.Thread.Thread ( ParameterizedThreadStart  start)

Initializes a new instance of the T:System.Threading.Thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started.

Parameters
startA delegate that represents the methods to be invoked when this thread begins executing.
Exceptions
T:System.ArgumentNullExceptionstart is null.

Definition at line 427 of file Thread.cs.

◆ Thread() [4/4]

System.Threading.Thread.Thread ( ParameterizedThreadStart  start,
int  maxStackSize 
)

Initializes a new instance of the T:System.Threading.Thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started and specifying the maximum stack size for the thread.

Parameters
startA T:System.Threading.ParameterizedThreadStart delegate that represents the methods to be invoked when this thread begins executing.
maxStackSizeThe maximum stack size, in bytes, to be used by the thread, or 0 to use the default maximum stack size specified in the header for the executable.Important   For partially trusted code, maxStackSize is ignored if it is greater than the default stack size. No exception is thrown.
Exceptions
T:System.ArgumentNullExceptionstart is null.
T:System.ArgumentOutOfRangeExceptionmaxStackSize is less than zero.

Definition at line 444 of file Thread.cs.

Member Function Documentation

◆ Abort() [1/2]

void System.Threading.Thread.Abort ( object  stateInfo)

Raises a T:System.Threading.ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread while also providing exception information about the thread termination. Calling this method usually terminates the thread.

Parameters
stateInfoAn object that contains application-specific information, such as state, which can be used by the thread being aborted.
Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.
T:System.Threading.ThreadStateExceptionThe thread that is being aborted is currently suspended.

Definition at line 601 of file Thread.cs.

◆ Abort() [2/2]

void System.Threading.Thread.Abort ( )

Raises a T:System.Threading.ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread. Calling this method usually terminates the thread.

Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.
T:System.Threading.ThreadStateExceptionThe thread that is being aborted is currently suspended.

Definition at line 612 of file Thread.cs.

◆ AllocateDataSlot()

static LocalDataStoreSlot System.Threading.Thread.AllocateDataSlot ( )
static

Allocates an unnamed data slot on all the threads. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead.

Returns
The allocated named data slot on all threads.

Definition at line 941 of file Thread.cs.

◆ AllocateNamedDataSlot()

static LocalDataStoreSlot System.Threading.Thread.AllocateNamedDataSlot ( string  name)
static

Allocates a named data slot on all threads. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead.

Parameters
nameThe name of the data slot to be allocated.
Returns
The allocated named data slot on all threads.
Exceptions
T:System.ArgumentExceptionA named data slot with the specified name already exists.

Definition at line 951 of file Thread.cs.

◆ BeginCriticalRegion()

static void System.Threading.Thread.BeginCriticalRegion ( )

Notifies a host that execution is about to enter a region of code in which the effects of a thread abort or unhandled exception might jeopardize other tasks in the application domain.

◆ BeginThreadAffinity()

static void System.Threading.Thread.BeginThreadAffinity ( )

Notifies a host that managed code is about to execute instructions that depend on the identity of the current physical operating system thread.

Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.

◆ DisableComObjectEagerCleanup()

void System.Threading.Thread.DisableComObjectEagerCleanup ( )

Turns off automatic cleanup of runtime callable wrappers (RCW) for the current thread.

◆ EndCriticalRegion()

static void System.Threading.Thread.EndCriticalRegion ( )

Notifies a host that execution is about to enter a region of code in which the effects of a thread abort or unhandled exception are limited to the current task.

◆ EndThreadAffinity()

static void System.Threading.Thread.EndThreadAffinity ( )

Notifies a host that managed code has finished executing instructions that depend on the identity of the current physical operating system thread.

Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.

◆ FreeNamedDataSlot()

static void System.Threading.Thread.FreeNamedDataSlot ( string  name)
static

Eliminates the association between a name and a slot, for all threads in the process. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead.

Parameters
nameThe name of the data slot to be freed.

Definition at line 968 of file Thread.cs.

◆ GetApartmentState()

ApartmentState System.Threading.Thread.GetApartmentState ( )

Returns an T:System.Threading.ApartmentState value indicating the apartment state.

Returns
One of the T:System.Threading.ApartmentState values indicating the apartment state of the managed thread. The default is F:System.Threading.ApartmentState.Unknown.

Definition at line 876 of file Thread.cs.

◆ GetCompressedStack()

CompressedStack System.Threading.Thread.GetCompressedStack ( )

Returns a T:System.Threading.CompressedStack object that can be used to capture the stack for the current thread.

Returns
None.
Exceptions
T:System.InvalidOperationExceptionIn all cases.

Definition at line 586 of file Thread.cs.

◆ GetData()

static object System.Threading.Thread.GetData ( LocalDataStoreSlot  slot)
static

Retrieves the value from the specified slot on the current thread, within the current thread's current domain. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead.

Parameters
slotThe T:System.LocalDataStoreSlot from which to get the value.
Returns
The retrieved value.

Definition at line 977 of file Thread.cs.

◆ GetDomain()

static AppDomain System.Threading.Thread.GetDomain ( )
static

Returns the current domain in which the current thread is running.

Returns
An T:System.AppDomain representing the current application domain of the running thread.

Definition at line 1096 of file Thread.cs.

◆ GetDomainID()

static int System.Threading.Thread.GetDomainID ( )
static

Returns a unique application domain identifier.

Returns
A 32-bit signed integer uniquely identifying the application domain.

Definition at line 1108 of file Thread.cs.

◆ GetHashCode()

override int System.Threading.Thread.GetHashCode ( )

Returns a hash code for the current thread.

Returns
An integer hash code value.

Definition at line 460 of file Thread.cs.

◆ GetNamedDataSlot()

static LocalDataStoreSlot System.Threading.Thread.GetNamedDataSlot ( string  name)
static

Looks up a named data slot. For better performance, use fields that are marked with the T:System.ThreadStaticAttribute attribute instead.

Parameters
nameThe name of the local data slot.
Returns
A T:System.LocalDataStoreSlot allocated for this thread.

Definition at line 960 of file Thread.cs.

◆ Interrupt()

void System.Threading.Thread.Interrupt ( )

Interrupts a thread that is in the WaitSleepJoin thread state.

Exceptions
T:System.Security.SecurityExceptionThe caller does not have the appropriate T:System.Security.Permissions.SecurityPermission.

Definition at line 677 of file Thread.cs.

◆ Join() [1/3]

void System.Threading.Thread.Join ( )

Blocks the calling thread until the thread represented by this instance terminates, while continuing to perform standard COM and SendMessage pumping.

Exceptions
T:System.Threading.ThreadStateExceptionThe caller attempted to join a thread that is in the F:System.Threading.ThreadState.Unstarted state.
T:System.Threading.ThreadInterruptedExceptionThe thread is interrupted while waiting.

Definition at line 703 of file Thread.cs.

◆ Join() [2/3]

bool System.Threading.Thread.Join ( int  millisecondsTimeout)

Blocks the calling thread until the thread represented by this instance terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping.

Parameters
millisecondsTimeoutThe number of milliseconds to wait for the thread to terminate.
Returns
true if the thread has terminated; false if the thread has not terminated after the amount of time specified by the millisecondsTimeout parameter has elapsed.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value of millisecondsTimeout is negative and is not equal to F:System.Threading.Timeout.Infinite in milliseconds.
T:System.Threading.ThreadStateExceptionThe thread has not been started.

Definition at line 716 of file Thread.cs.

◆ Join() [3/3]

bool System.Threading.Thread.Join ( TimeSpan  timeout)

Blocks the calling thread until the thread represented by this instance terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping.

Parameters
timeoutA T:System.TimeSpan set to the amount of time to wait for the thread to terminate.
Returns
true if the thread terminated; false if the thread has not terminated after the amount of time specified by the timeout parameter has elapsed.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value of timeout is negative and is not equal to F:System.Threading.Timeout.Infinite in milliseconds, or is greater than F:System.Int32.MaxValue milliseconds.
T:System.Threading.ThreadStateExceptionThe caller attempted to join a thread that is in the F:System.Threading.ThreadState.Unstarted state.

Definition at line 728 of file Thread.cs.

◆ MemoryBarrier()

static void System.Threading.Thread.MemoryBarrier ( )

Synchronizes memory access as follows: The processor executing the current thread cannot reorder instructions in such a way that memory accesses prior to the call to M:System.Threading.Thread.MemoryBarrier execute after memory accesses that follow the call to M:System.Threading.Thread.MemoryBarrier.

◆ ResetAbort()

static void System.Threading.Thread.ResetAbort ( )
static

Cancels an M:System.Threading.Thread.Abort(System.Object) requested for the current thread.

Exceptions
T:System.Threading.ThreadStateExceptionAbort was not invoked on the current thread.
T:System.Security.SecurityExceptionThe caller does not have the required security permission for the current thread.

Definition at line 627 of file Thread.cs.

◆ Resume()

void System.Threading.Thread.Resume ( )

Resumes a thread that has been suspended.

Exceptions
T:System.Threading.ThreadStateExceptionThe thread has not been started, is dead, or is not in the suspended state.
T:System.Security.SecurityExceptionThe caller does not have the appropriate T:System.Security.Permissions.SecurityPermission.

Definition at line 664 of file Thread.cs.

◆ SetApartmentState()

void System.Threading.Thread.SetApartmentState ( ApartmentState  state)

Sets the apartment state of a thread before it is started.

Parameters
stateThe new apartment state.
Exceptions
T:System.ArgumentExceptionstate is not a valid apartment state.
T:System.Threading.ThreadStateExceptionThe thread has already been started.
T:System.InvalidOperationExceptionThe apartment state has already been initialized.

Definition at line 903 of file Thread.cs.

◆ SetCompressedStack()

void System.Threading.Thread.SetCompressedStack ( CompressedStack  stack)

Applies a captured T:System.Threading.CompressedStack to the current thread.

Parameters
stackThe T:System.Threading.CompressedStack object to be applied to the current thread.
Exceptions
T:System.InvalidOperationExceptionIn all cases.

Definition at line 565 of file Thread.cs.

◆ SetData()

static void System.Threading.Thread.SetData ( LocalDataStoreSlot  slot,
object  data 
)
static

Sets the data in the specified slot on the currently running thread, for that thread's current domain. For better performance, use fields marked with the T:System.ThreadStaticAttribute attribute instead.

Parameters
slotThe T:System.LocalDataStoreSlot in which to set the value.
dataThe value to be set.

Definition at line 992 of file Thread.cs.

◆ Sleep() [1/2]

static void System.Threading.Thread.Sleep ( int  millisecondsTimeout)
static

Suspends the current thread for the specified number of milliseconds.

Parameters
millisecondsTimeoutThe number of milliseconds for which the thread is suspended. If the value of the millisecondsTimeout argument is zero, the thread relinquishes the remainder of its time slice to any thread of equal priority that is ready to run. If there are no other threads of equal priority that are ready to run, execution of the current thread is not suspended.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe time-out value is negative and is not equal to F:System.Threading.Timeout.Infinite.

Definition at line 746 of file Thread.cs.

◆ Sleep() [2/2]

static void System.Threading.Thread.Sleep ( TimeSpan  timeout)
static

Suspends the current thread for the specified amount of time.

Parameters
timeoutThe amount of time for which the thread is suspended. If the value of the millisecondsTimeout argument is F:System.TimeSpan.Zero, the thread relinquishes the remainder of its time slice to any thread of equal priority that is ready to run. If there are no other threads of equal priority that are ready to run, execution of the current thread is not suspended.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe value of timeout is negative and is not equal to F:System.Threading.Timeout.Infinite in milliseconds, or is greater than F:System.Int32.MaxValue milliseconds.

Definition at line 758 of file Thread.cs.

◆ SpinWait()

static void System.Threading.Thread.SpinWait ( int  iterations)
static

Causes a thread to wait the number of times defined by the iterations parameter.

Parameters
iterationsA 32-bit signed integer that defines how long a thread is to wait.

Definition at line 779 of file Thread.cs.

◆ Start() [1/2]

void System.Threading.Thread.Start ( )

Causes the operating system to change the state of the current instance to F:System.Threading.ThreadState.Running.

Exceptions
T:System.Threading.ThreadStateExceptionThe thread has already been started.
T:System.OutOfMemoryExceptionThere is not enough memory available to start this thread.

Definition at line 480 of file Thread.cs.

◆ Start() [2/2]

void System.Threading.Thread.Start ( object  parameter)

Causes the operating system to change the state of the current instance to F:System.Threading.ThreadState.Running, and optionally supplies an object containing data to be used by the method the thread executes.

Parameters
parameterAn object that contains data to be used by the method the thread executes.
Exceptions
T:System.Threading.ThreadStateExceptionThe thread has already been started.
T:System.OutOfMemoryExceptionThere is not enough memory available to start this thread.
T:System.InvalidOperationExceptionThis thread was created using a T:System.Threading.ThreadStart delegate instead of a T:System.Threading.ParameterizedThreadStart delegate.

Definition at line 493 of file Thread.cs.

◆ Suspend()

void System.Threading.Thread.Suspend ( )

Either suspends the thread, or if the thread is already suspended, has no effect.

Exceptions
T:System.Threading.ThreadStateExceptionThe thread has not been started or is dead.
T:System.Security.SecurityExceptionThe caller does not have the appropriate T:System.Security.Permissions.SecurityPermission.

Definition at line 649 of file Thread.cs.

◆ TrySetApartmentState()

bool System.Threading.Thread.TrySetApartmentState ( ApartmentState  state)

Sets the apartment state of a thread before it is started.

Parameters
stateThe new apartment state.
Returns
true if the apartment state is set; otherwise, false.
Exceptions
T:System.ArgumentExceptionstate is not a valid apartment state.
T:System.Threading.ThreadStateExceptionThe thread has already been started.

Definition at line 890 of file Thread.cs.

◆ VolatileRead() [1/13]

static byte System.Threading.Thread.VolatileRead ( ref byte  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1150 of file Thread.cs.

◆ VolatileRead() [2/13]

static short System.Threading.Thread.VolatileRead ( ref short  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1161 of file Thread.cs.

◆ VolatileRead() [3/13]

static int System.Threading.Thread.VolatileRead ( ref int  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1172 of file Thread.cs.

◆ VolatileRead() [4/13]

static long System.Threading.Thread.VolatileRead ( ref long  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1183 of file Thread.cs.

◆ VolatileRead() [5/13]

static sbyte System.Threading.Thread.VolatileRead ( ref sbyte  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1195 of file Thread.cs.

◆ VolatileRead() [6/13]

static ushort System.Threading.Thread.VolatileRead ( ref ushort  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1207 of file Thread.cs.

◆ VolatileRead() [7/13]

static uint System.Threading.Thread.VolatileRead ( ref uint  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1219 of file Thread.cs.

◆ VolatileRead() [8/13]

static IntPtr System.Threading.Thread.VolatileRead ( ref IntPtr  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1230 of file Thread.cs.

◆ VolatileRead() [9/13]

static UIntPtr System.Threading.Thread.VolatileRead ( ref UIntPtr  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1242 of file Thread.cs.

◆ VolatileRead() [10/13]

static ulong System.Threading.Thread.VolatileRead ( ref ulong  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1254 of file Thread.cs.

◆ VolatileRead() [11/13]

static float System.Threading.Thread.VolatileRead ( ref float  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1265 of file Thread.cs.

◆ VolatileRead() [12/13]

static double System.Threading.Thread.VolatileRead ( ref double  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1276 of file Thread.cs.

◆ VolatileRead() [13/13]

static object System.Threading.Thread.VolatileRead ( ref object  address)
static

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

Parameters
addressThe field to be read.
Returns
The latest value written to the field by any processor.

Definition at line 1287 of file Thread.cs.

◆ VolatileWrite() [1/13]

static void System.Threading.Thread.VolatileWrite ( ref byte  address,
byte  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1298 of file Thread.cs.

◆ VolatileWrite() [2/13]

static void System.Threading.Thread.VolatileWrite ( ref short  address,
short  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1308 of file Thread.cs.

◆ VolatileWrite() [3/13]

static void System.Threading.Thread.VolatileWrite ( ref int  address,
int  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1318 of file Thread.cs.

◆ VolatileWrite() [4/13]

static void System.Threading.Thread.VolatileWrite ( ref long  address,
long  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1328 of file Thread.cs.

◆ VolatileWrite() [5/13]

static void System.Threading.Thread.VolatileWrite ( ref sbyte  address,
sbyte  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1339 of file Thread.cs.

◆ VolatileWrite() [6/13]

static void System.Threading.Thread.VolatileWrite ( ref ushort  address,
ushort  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1350 of file Thread.cs.

◆ VolatileWrite() [7/13]

static void System.Threading.Thread.VolatileWrite ( ref uint  address,
uint  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1361 of file Thread.cs.

◆ VolatileWrite() [8/13]

static void System.Threading.Thread.VolatileWrite ( ref IntPtr  address,
IntPtr  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1371 of file Thread.cs.

◆ VolatileWrite() [9/13]

static void System.Threading.Thread.VolatileWrite ( ref UIntPtr  address,
UIntPtr  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1382 of file Thread.cs.

◆ VolatileWrite() [10/13]

static void System.Threading.Thread.VolatileWrite ( ref ulong  address,
ulong  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1393 of file Thread.cs.

◆ VolatileWrite() [11/13]

static void System.Threading.Thread.VolatileWrite ( ref float  address,
float  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1403 of file Thread.cs.

◆ VolatileWrite() [12/13]

static void System.Threading.Thread.VolatileWrite ( ref double  address,
double  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1413 of file Thread.cs.

◆ VolatileWrite() [13/13]

static void System.Threading.Thread.VolatileWrite ( ref object  address,
object  value 
)
static

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

Parameters
addressThe field to which the value is to be written.
valueThe value to be written.

Definition at line 1423 of file Thread.cs.

◆ Yield()

static bool System.Threading.Thread.Yield ( )
static

Causes the calling thread to yield execution to another thread that is ready to run on the current processor. The operating system selects the thread to yield to.

Returns
true if the operating system switched execution to another thread; otherwise, false.

Definition at line 797 of file Thread.cs.

Property Documentation

◆ ApartmentState

ApartmentState System.Threading.Thread.ApartmentState
getset

Gets or sets the apartment state of this thread.

Returns
One of the T:System.Threading.ApartmentState values. The initial value is Unknown.
Exceptions
T:System.ArgumentExceptionAn attempt is made to set this property to a state that is not a valid apartment state (a state other than single-threaded apartment (STA) or multithreaded apartment (MTA)).

Definition at line 179 of file Thread.cs.

◆ CurrentContext

Context System.Threading.Thread.CurrentContext
staticget

Gets the current context in which the thread is executing.

Returns
A T:System.Runtime.Remoting.Contexts.Context representing the current thread context.
Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 285 of file Thread.cs.

◆ CurrentCulture

CultureInfo?? System.Threading.Thread.CurrentCulture
getset

Gets or sets the culture for the current thread.

Returns
An object that represents the culture for the current thread.
Exceptions
T:System.ArgumentNullExceptionThe property is set to null.

Definition at line 245 of file Thread.cs.

◆ CurrentPrincipal

IPrincipal System.Threading.Thread.CurrentPrincipal
staticgetset

Gets or sets the thread's current principal (for role-based security).

Returns
An T:System.Security.Principal.IPrincipal value representing the security context.
Exceptions
T:System.Security.SecurityExceptionThe caller does not have the permission required to set the principal.

Definition at line 297 of file Thread.cs.

◆ CurrentThread

Thread System.Threading.Thread.CurrentThread
staticget

Gets the currently running thread.

Returns
A T:System.Threading.Thread that is the representation of the currently running thread.

Definition at line 134 of file Thread.cs.

◆ CurrentUICulture

CultureInfo?? System.Threading.Thread.CurrentUICulture
getset

Gets or sets the current culture used by the Resource Manager to look up culture-specific resources at run time.

Returns
An object that represents the current culture.
Exceptions
T:System.ArgumentNullExceptionThe property is set to null.
T:System.ArgumentExceptionThe property is set to a culture name that cannot be used to locate a resource file. Resource filenames must include only letters, numbers, hyphens or underscores.

Definition at line 199 of file Thread.cs.

◆ ExecutionContext

ExecutionContext System.Threading.Thread.ExecutionContext
get

Gets an T:System.Threading.ExecutionContext object that contains information about the various contexts of the current thread.

Returns
An T:System.Threading.ExecutionContext object that consolidates context information for the current thread.

Definition at line 78 of file Thread.cs.

◆ IsAlive

bool System.Threading.Thread.IsAlive
get

Gets a value indicating the execution status of the current thread.

Returns
true if this thread has been started and has not terminated normally or aborted; otherwise, false.

Definition at line 114 of file Thread.cs.

◆ IsBackground

bool System.Threading.Thread.IsBackground
getset

Gets or sets a value indicating whether or not a thread is a background thread.

Returns
true if this thread is or is to become a background thread; otherwise, false.
Exceptions
T:System.Threading.ThreadStateExceptionThe thread is dead.

Definition at line 149 of file Thread.cs.

◆ IsThreadPoolThread

bool System.Threading.Thread.IsThreadPoolThread
get

Gets a value indicating whether or not a thread belongs to the managed thread pool.

Returns
true if this thread belongs to the managed thread pool; otherwise, false.

Definition at line 124 of file Thread.cs.

◆ ManagedThreadId

int System.Threading.Thread.ManagedThreadId
get

Gets a unique identifier for the current managed thread.

Returns
An integer that represents a unique identifier for this managed thread.

Definition at line 55 of file Thread.cs.

◆ Name

string??? System.Threading.Thread.Name
getset

Gets or sets the name of the thread.

Returns
A string containing the name of the thread, or null if no name was set.
Exceptions
T:System.InvalidOperationExceptionA set operation was requested, but the Name property has already been set.

Definition at line 323 of file Thread.cs.

◆ Priority

ThreadPriority System.Threading.Thread.Priority
getset

Gets or sets a value indicating the scheduling priority of a thread.

Returns
One of the T:System.Threading.ThreadPriority values. The default value is F:System.Threading.ThreadPriority.Normal.
Exceptions
T:System.Threading.ThreadStateExceptionThe thread has reached a final state, such as F:System.Threading.ThreadState.Aborted.
T:System.ArgumentExceptionThe value specified for a set operation is not a valid T:System.Threading.ThreadPriority value.

Definition at line 96 of file Thread.cs.

◆ ThreadState

ThreadState System.Threading.Thread.ThreadState
get

Gets a value containing the states of the current thread.

Returns
One of the T:System.Threading.ThreadState values indicating the state of the current thread. The initial value is Unstarted.

Definition at line 166 of file Thread.cs.


The documentation for this class was generated from the following file: