System.Threading.Thread Class

public sealed class Thread

Base Types

Object
  Thread

Assembly

mscorlib

Library

BCL

Summary

Represents a sequential thread of execution.

Description

A process can create and execute one or more threads to execute a portion of the program code associated with the process. A ThreadStart delegate is used to specify the program code executed by a thread.

Some operating systems might not utilize the concepts of threads or preemptive scheduling. Also, the concept of "thread priority" might not exist at all or its meaning might vary, depending on the underlying operating system. Implementers of the Thread type are required to describe their threading policies, including what thread priority means, how many threading priority levels exist, and whether scheduling is preemptive.

For the duration of its existence, a thread is always in one or more of the states defined by ThreadState. A scheduling priority level, as defined by ThreadPriority , can be requested for a thread, but it might not be honored by the operating system.

If an unhandled exception is thrown in the code executed by a thread created by an application, a System.AppDomain.UnhandledException event is raised (System.UnhandledExceptionEventArgs.IsTerminating is set to false ), and the thread is terminated; the current process is not terminated.

See Also

System.Threading Namespace

Members

Thread Constructors

Thread Constructor

Thread Methods

Thread.Abort(System.Object) Method
Thread.Abort() Method
Thread.Finalize Method
Thread.GetDomain Method
Thread.Join() Method
Thread.Join(System.TimeSpan) Method
Thread.Join(int) Method
Thread.MemoryBarrier Method
Thread.ResetAbort Method
Thread.Sleep(int) Method
Thread.Sleep(System.TimeSpan) Method
Thread.Start Method
Thread.VolatileRead(System.Object&) Method
Thread.VolatileRead(System.Double&) Method
Thread.VolatileRead(System.Single&) Method
Thread.VolatileRead(System.UInt64&) Method
Thread.VolatileRead(System.UIntPtr&) Method
Thread.VolatileRead(System.IntPtr&) Method
Thread.VolatileRead(System.UInt32&) Method
Thread.VolatileRead(System.UInt16&) Method
Thread.VolatileRead(System.SByte&) Method
Thread.VolatileRead(System.Int64&) Method
Thread.VolatileRead(System.Int32&) Method
Thread.VolatileRead(System.Int16&) Method
Thread.VolatileRead(System.Byte&) Method
Thread.VolatileWrite(System.UInt32&, uint) Method
Thread.VolatileWrite(System.UInt64&, ulong) Method
Thread.VolatileWrite(System.UIntPtr&, System.UIntPtr) Method
Thread.VolatileWrite(System.IntPtr&, System.IntPtr) Method
Thread.VolatileWrite(System.Single&, float) Method
Thread.VolatileWrite(System.Double&, double) Method
Thread.VolatileWrite(System.Object&, System.Object) Method
Thread.VolatileWrite(System.UInt16&, ushort) Method
Thread.VolatileWrite(System.SByte&, sbyte) Method
Thread.VolatileWrite(System.Int64&, long) Method
Thread.VolatileWrite(System.Int32&, int) Method
Thread.VolatileWrite(System.Int16&, short) Method
Thread.VolatileWrite(System.Byte&, byte) Method

Thread Properties

Thread.CurrentThread Property
Thread.IsAlive Property
Thread.IsBackground Property
Thread.Name Property
Thread.Priority Property
Thread.ThreadState Property


Thread Constructor

public Thread(ThreadStart start);

Summary

Constructs and initializes a new instance of the Thread class.

Parameters

start
A ThreadStart delegate that references the methods to be invoked when the new thread begins executing.

Exceptions

Exception TypeCondition
ArgumentNullExceptionstart is null .

Description

[Note: To schedule the thread for execution, call System.Threading.Thread.Start.]

Until System.Threading.Thread.Start is called, the thread's state includes System.Threading.ThreadState.Unstarted.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Abort(System.Object) Method

public void Abort(object stateInfo);

Summary

Raises a ThreadAbortException in the thread on which it is invoked to begin the process of terminating the thread. In all but the most extraordinary situations, calling this method will terminate the thread.

Parameters

stateInfo
A Object that contains application-specific information, such as state, which can be used by the thread being aborted.

Exceptions

Exception TypeCondition
SecurityExceptionCaller does not have System.Security.Permissions.SecurityPermissionFlag.ControlThread security permission for this thread.

Description

The object passed as the stateInfo parameter can be obtained by accessing the System.Threading.ThreadAbortException.ExceptionState property.

[Note: For details on aborting threads, see System.Threading.Thread.Abort(System.Object) ().]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Abort() Method

public void Abort();

Summary

Raises a ThreadAbortException in the thread on which it is invoked to begin the process of terminating the thread. In all but the most extraordinary situations, calling this method will terminate the thread.

Exceptions

Exception TypeCondition
SecurityExceptionCaller does not have System.Security.Permissions.SecurityPermissionFlag.ControlThread security permission for the thread to be aborted.

Description

When this method is invoked on a thread, the system throws a ThreadAbortException in the thread to abort it. Invoking System.Threading.Thread.Abort(System.Object) on a thread is similar to arranging for the target thread to throw a ThreadAbortException. Because, unlike other exceptions, a ThreadAbortException is sent to another thread, the exception might be delayed. A ThreadAbortException is required to be delayed if and while the target thread is executing any of the following:

A thread abort proceeds as follows:

  1. An abort begins at the earliest of the following times:

    a. when the thread transitions from unmanaged to managed code execution;

    b. when the thread finishes the outermost currently executing catch handler;

    c. immediately if the thread is running managed code outside of any catch handler, finally clause, filter clause or type initializer

  2. Whenever an outermost catch handler finishes execution, the ThreadAbortException is rethrown unless the thread being aborted has called System.Threading.Thread.ResetAbort since the call to System.Threading.Thread.Abort(System.Object).

  3. When all finally blocks have been called and the thread is about to transition to any unmanaged code which executed before the first entry to managed code, System.Threading.Thread.ResetAbort is called so that a return to managed code will consider the abort to have been successfully processed.

Unexecuted finally blocks are executed before the thread is aborted; this includes any finally block that is executing when the exception is thrown. The thread is not guaranteed to abort immediately, or at all. This situation can occur if a thread does an unbounded amount of computation in the finally blocks that are called as part of the abort procedure, thereby indefinitely delaying the abort. To ensure a thread has aborted, invoke System.Threading.Thread.Join on the thread after calling System.Threading.Thread.Abort(System.Object) .

If System.Threading.Thread.Abort(System.Object) is called on a thread that has not been started, the thread aborts when System.Threading.Thread.Start is called. If the target thread is blocked or sleeping in managed code and is not inside any of the code blocks that are required to delay an abort, the thread is resumed and immediately aborted.

After System.Threading.Thread.Abort(System.Object) is invoked on a thread, the state of the thread includes System.Threading.ThreadState.AbortRequested. After the thread has terminated as a result of a successful call to System.Threading.Thread.Abort(System.Object), the state of the thread includes System.Threading.ThreadState.Stopped and System.Threading.ThreadState.Aborted .

[Note: With sufficient permissions, a thread that is the target of a System.Threading.Thread.Abort(System.Object) can cancel the abort using the System.Threading.Thread.ResetAbort method. For an example that demonstrates calling the System.Threading.Thread.ResetAbort method, see ThreadAbortException .]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Finalize Method

~Thread();

Summary

Releases the resources held by this instance.

Description

[Note: Application code does not call this method; it is automatically invoked during garbage collection.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.GetDomain Method

public static AppDomain GetDomain();

Summary

Returns an object representing the application domain in which the current thread is executing.

Return Value

A AppDomain object that represents the current application domain.

Library

RuntimeInfrastructure

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Join() Method

public void Join();

Summary

Blocks the calling thread until the thread on which this method is invoked terminates.

Exceptions

Exception TypeCondition
ThreadStateExceptionThe caller attempted to join a thread that is in the System.Threading.ThreadState.Unstarted state.

Description

[Note: Use this method to ensure a thread has terminated. The caller will block indefinitely if the thread does not terminate.]

System.Threading.Thread.Join cannot be invoked on a thread that is in the System.Threading.ThreadState.Unstarted state.

This method changes the state of the calling thread to include System.Threading.ThreadState.WaitSleepJoin.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Join(System.TimeSpan) Method

public bool Join(TimeSpan timeout);

Summary

Blocks the calling thread until the thread on which this method is invoked terminates or the specified time elapses.

Parameters

timeout
A TimeSpan set to the amount of time to wait for the thread to terminate. Specify System.Threading.Timeout.Infinite milliseconds to wait indefinitely.

Return Value

true if the thread has terminated; false if the thread has not terminated after the amount of time specified by timeout has elapsed.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe value of timeout is negative and is not equal to System.Threading.Timeout.Infinite milliseconds, or is greater than System.Int32.MaxValue milliseconds.
ThreadStateExceptionThe caller attempted to join a thread that is in the System.Threading.ThreadState.Unstarted state.

Description

This method converts timeout to milliseconds, tests the validity of the converted value, and calls System.Threading.Thread.Join(Int32).

[Note: If System.Threading.Timeout.Infinite milliseconds is specified for timeout, this method behaves identically to Join (), except for the return value.]

Join cannot be invoked on a thread that is in the System.Threading.ThreadState.Unstarted state.

This method changes the state of the current thread to include System.Threading.ThreadState.WaitSleepJoin.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Join(int) Method

public bool Join(int millisecondsTimeout);

Summary

Blocks the calling thread until the thread on which this method is invoked terminates or the specified time elapses.

Parameters

millisecondsTimeout
A Int32 containing the number of milliseconds to wait for the thread to terminate.

Return Value

true if the thread has terminated; false if the thread has not terminated after millisecondsTimeout has elapsed.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe value of millisecondsTimeout is negative and is not equal to System.Threading.Timeout.Infinite .
ThreadStateExceptionThe caller attempted to join a thread that is in the System.Threading.ThreadState.Unstarted state.

Description

[Note: If System.Threading.Timeout.Infinite is specified for millisecondsTimeout, this method behaves identically to Join (), except for the return value.]

Join cannot be invoked on a thread that is in the System.Threading.ThreadState.Unstarted state.

This method changes the state of the calling thread to include System.Threading.ThreadState.WaitSleepJoin.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.MemoryBarrier Method

public static void MemoryBarrier ();

Summary

Guarantees that all subsequent loads or stores from the current thread will not access memory until after all previous loads and stores from the current thread have completed, as observed from this or other threads.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.ResetAbort Method

public static void ResetAbort();

Summary

Cancels a System.Threading.Thread.Abort(System.Object) requested for the current thread.

Exceptions

Exception TypeCondition
ThreadStateExceptionSystem.Threading.Thread.Abort(System.Object) was not invoked on the current thread.
SecurityExceptionCaller does not have System.Security.Permissions.SecurityPermissionFlag.ControlThread security permission for the current thread.

Description

This method cannot be called by untrusted code.

When a call is made to System.Threading.Thread.Abort(System.Object) to destroy a thread, the system throws a ThreadAbortException. ThreadAbortException is a special exception that can be caught by application code, but is rethrown at the end of the catch block unless ResetAbort is called. ResetAbort cancels the request to abort, and prevents the ThreadAbortException from terminating the thread.

Example

For an example that demonstrates calling this method, see ThreadAbortException .

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Sleep(int) Method

public static void Sleep(int millisecondsTimeout);

Summary

Blocks the current thread for the specified number of milliseconds.

Parameters

millisecondsTimeout
A Int32 containing the number of milliseconds for which the thread is blocked. Specify zero to indicate that this thread should be suspended temporarily to allow other waiting threads to execute. Specify System.Threading.Timeout.Infinite to block the thread indefinitely.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe value of millisecondsTimeout is negative and is not equal to System.Threading.Timeout.Infinite .

Description

The thread will not be scheduled for execution by the operating system for the amount of time specified. This method changes the state of the thread to include System.Threading.ThreadState.WaitSleepJoin.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Sleep(System.TimeSpan) Method

public static void Sleep(TimeSpan timeout);

Summary

Blocks the current thread for a specified time.

Parameters

timeout
A TimeSpan set to the amount of time for which the current thread will be blocked. Specify zero to indicate that this thread should be suspended temporarily to allow other waiting threads to execute. Specify System.Threading.Timeout.Infinite milliseconds to suspend the thread indefinitely.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionThe value of timeout is negative and is not equal to System.Threading.Timeout.Infinite milliseconds, or is greater than System.Int32.MaxValue milliseconds.

Description

This method converts timeout to milliseconds, tests the validity of the converted value, and calls System.Threading.Thread.Sleep(System.Int32)(Int32).

The thread will not be scheduled for execution by the operating system for the amount of time specified. This method changes the state of the thread to include System.Threading.ThreadState.WaitSleepJoin.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Start Method

public void Start();

Summary

Causes the operating system to consider the thread ready to be scheduled for execution.

Exceptions

Exception TypeCondition
OutOfMemoryExceptionThere is not enough memory available to start the thread.
NullReferenceExceptionThis method was invoked on a null thread reference.
ThreadStateExceptionThe thread has already been started.

Description

Calling System.Threading.Thread.Start removes the System.Threading.ThreadState.Unstarted state from the System.Threading.Thread.ThreadState of the thread.

Once a thread is started, the operating system can schedule it for execution. When the thread begins executing, the ThreadStart delegate supplied to the constructor for the thread invokes its methods.

Once the thread terminates, it cannot be restarted with another call to System.Threading.Thread.Start.

Example

The following example demonstrates creating a thread and starting it.

using System;
using System.Threading;
public class ThreadWork {
  public static void DoWork() {
    for (int i = 0; i<3;i++) {
         Console.WriteLine ("Working thread ...");
         Thread.Sleep(100);
    }
  }
}
class ThreadTest{
  public static void Main() {
    ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);
    Thread myThread = new Thread(myThreadDelegate);
    myThread.Start();
    for (int i = 0; i<3; i++) {
        Console.WriteLine("In main.");
        Thread.Sleep(100);
    }
  }
}
   
One possible set of output is

In main.

Working thread ...

In main.

Working thread ...

In main.

Working thread ...

Note that the sequence of the output statements is not guaranteed to be identical across systems.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.Object&) Method

public static object VolatileRead (ref object address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a Object that specifies the address in memory from which to read.

Return Value

A Object containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.Double&) Method

public static double VolatileRead (ref double address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a Double that specifies the address in memory from which to read.

Return Value

A Double containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.Single&) Method

public static float VolatileRead (ref float address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a Single that specifies the address in memory from which to read.

Return Value

A Single containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.UInt64&) Method

public static ulong VolatileRead (ref ulong address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a UInt64 that specifies the address in memory from which to read.

Return Value

A UInt64 containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.UIntPtr&) Method

public static UIntPtr VolatileRead (ref UIntPtr address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a UIntPtr that specifies the address in memory from which to read.

Return Value

A UIntPtr containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

Library

RuntimeInfrastructure

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.IntPtr&) Method

public static IntPtr VolatileRead (ref IntPtr address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a IntPtr that specifies the address in memory from which to read.

Return Value

A IntPtr containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

Library

RuntimeInfrastructure

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.UInt32&) Method

public static uint VolatileRead (ref uint address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a UInt32 that specifies the address in memory from which to read.

Return Value

A UInt32 containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.UInt16&) Method

public static ushort VolatileRead (ref ushort address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a UInt16 that specifies the address in memory from which to read.

Return Value

A UInt16 containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.SByte&) Method

public static sbyte VolatileRead (ref sbyte address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a SByte that specifies the address in memory from which to read.

Return Value

A SByte containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.Int64&) Method

public static long VolatileRead (ref long address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a Int64 that specifies the address in memory from which to read.

Return Value

A Int64 containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.Int32&) Method

public static int VolatileRead (ref int address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a Int32 that specifies the address in memory from which to read.

Return Value

A Int32 containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.Int16&) Method

public static short VolatileRead (ref short address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a Int16 that specifies the address in memory from which to read.

Return Value

A Int16 containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileRead(System.Byte&) Method

public static byte VolatileRead (ref byte address);

Summary

Performs a volatile read from the specified address.

Parameters

address
A reference to a Byte that specifies the address in memory from which to read.

Return Value

A Byte containing the value at the specified address after any pending writes.

Description

The value at the given address is atomically loaded with acquire semantics, meaning that the read is guaranteed to occur prior to any references to memory that occur after the execution of this method in the current thread. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileWrite if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the load CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.UInt32&, uint) Method

public static void VolatileWrite (ref uint address, uint value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a UInt32 that specifies the address in memory at which to write.
value
A UInt32 that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.UInt64&, ulong) Method

public static void VolatileWrite (ref ulong address, ulong value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a UInt64 that specifies the address in memory at which to write.
value
A UInt64 that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.UIntPtr&, System.UIntPtr) Method

public static void VolatileWrite (ref UIntPtr address, UIntPtr value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a UIntPtr that specifies the address in memory at which to write.
value
A UIntPtr that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

Library

RuntimeInfrastructure

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.IntPtr&, System.IntPtr) Method

public static void VolatileWrite (ref IntPtr address, IntPtr value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a IntPtr that specifies the address in memory at which to write.
value
A IntPtr that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

Library

RuntimeInfrastructure

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.Single&, float) Method

public static void VolatileWrite (ref float address, float value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a Single that specifies the address in memory at which to write.
value
A Single that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.Double&, double) Method

public static void VolatileWrite (ref double address, double value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a Double that specifies the address in memory at which to write.
value
A Double that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.Object&, System.Object) Method

public static void VolatileWrite (ref object address, object value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a Object that specifies the address in memory at which to write.
value
A Object that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.UInt16&, ushort) Method

public static void VolatileWrite (ref ushort address, ushort value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a UInt16 that specifies the address in memory at which to write.
value
A UInt16 that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.SByte&, sbyte) Method

public static void VolatileWrite (ref sbyte address, sbyte value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a SByte that specifies the address in memory at which to write.
value
A SByte that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.Int64&, long) Method

public static void VolatileWrite (ref long address, long value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a Int64 that specifies the address in memory at which to write.
value
A Int64 that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.Int32&, int) Method

public static void VolatileWrite (ref int address, int value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a Int32 that specifies the address in memory at which to write.
value
A Int32 that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.Int16&, short) Method

public static void VolatileWrite (ref short address, short value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a Int16 that specifies the address in memory at which to write.
value
A Int16 that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.VolatileWrite(System.Byte&, byte) Method

public static void VolatileWrite (ref byte address, byte value);

Summary

Performs a volatile write to the specified address.

Parameters

address
A reference to a Byte that specifies the address in memory at which to write.
value
A Byte that specifies the value to write.

Description

The value is written atomically to the specified address with release semantics, meaning that the write is guaranteed to happen after any references to memory that occur prior to the execution. It is recommended that System.Threading.Thread.VolatileRead and System.Threading.Thread.VolatileWrite be used in conjunction. Calling this method affects only this single access; other accesses to the same location are required to also be made using this method or System.Threading.Thread.VolatileRead if the volatile semantics are to be preserved. This method has exactly the same semantics as using the volatile prefix on the store CIL instruction, except that atomicity is provided for all types, not just those 32 bits or smaller in size. [Note: For additional information, see Partition I of the CLI Specification.]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.CurrentThread Property

public static Thread CurrentThread { get; }

Summary

Gets a Thread instance that represents the currently executing thread.

Property Value

An instance of Thread representing the current thread.

Description

This property is read-only.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.IsAlive Property

public bool IsAlive { get; }

Summary

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

Property Value

true if this thread has been started, and has not terminated; otherwise, false .

Description

This property is read-only.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.IsBackground Property

public bool IsBackground { get; set; }

Summary

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

Property Value

true if the thread is or is to become a background thread; otherwise, false .

Exceptions

Exception TypeCondition
ThreadStateException The thread has reached the System.Threading.ThreadState.Stopped state.

Description

The default value of this property is false . The property value can be changed before the thread is started and before it terminates.

[Note: A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads except for the fact that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the execution engine ends the process by invoking System.Threading.Thread.Abort(System.Object) on any background threads that are still alive. ]

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Name Property

public string Name { get; set; }

Summary

Gets or sets the name of the thread.

Property Value

A String containing the name of the thread, or null if no name was set.

Exceptions

Exception TypeCondition
InvalidOperationExceptionA set operation was requested, and the Name property has already been set.

Description

This property is write-once. Once this property has been set to a non-null value, attempts to set this property to a new value cause an exception.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.Priority Property

public ThreadPriority Priority { get; set; }

Summary

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

Property Value

A ThreadPriority value.

Exceptions

Exception TypeCondition
ThreadStateException The thread is in the System.Threading.ThreadState.Stopped state.
ArgumentExceptionThe value specified for a set operation is not a valid ThreadPriority value.

Description

A thread can be assigned any one of the following priority values:

The default value is System.Threading.ThreadPriority.Normal.

Operating systems are not required to honor the priority of a thread.

See Also

System.Threading.Thread Class, System.Threading Namespace

Thread.ThreadState Property

public ThreadState ThreadState { get; }

Summary

Gets a value containing the states of the current thread.

Property Value

A combination of one or more ThreadState values, which indicate the state of the current thread.

Description

This property is read-only.

A thread is running if the value returned by this property does not include System.Threading.ThreadState.Unstarted and does not include System.Threading.ThreadState.Stopped.

See Also

System.Threading.Thread Class, System.Threading Namespace