public sealed class Thread
Object
Thread
mscorlib
BCL
Represents a sequential thread of execution.
A process may 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 may 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.
System.Threading Namespace
Thread Constructors
Thread Methods
Thread.Abort(System.Object) Method
Thread.Abort() Method
Thread.Finalize Method
Thread.GetDomain Method
Thread.Join() Method
Thread.Join(int) Method
Thread.Join(System.TimeSpan) Method
Thread.MemoryBarrier Method
Thread.ResetAbort Method
Thread.Sleep(int) Method
Thread.Sleep(System.TimeSpan) Method
Thread.Start Method
Thread.VolatileRead(System.Byte&) Method
Thread.VolatileRead(System.Int16&) Method
Thread.VolatileRead(System.Int32&) Method
Thread.VolatileRead(System.Int64&) Method
Thread.VolatileRead(System.SByte&) Method
Thread.VolatileRead(System.UInt16&) Method
Thread.VolatileRead(System.UInt32&) Method
Thread.VolatileRead(System.IntPtr&) Method
Thread.VolatileRead(System.UIntPtr&) Method
Thread.VolatileRead(System.UInt64&) Method
Thread.VolatileRead(System.Single&) Method
Thread.VolatileRead(System.Double&) Method
Thread.VolatileRead(System.Object&) Method
Thread.VolatileWrite(System.Byte&, byte) Method
Thread.VolatileWrite(System.Int16&, short) Method
Thread.VolatileWrite(System.Int32&, int) Method
Thread.VolatileWrite(System.Int64&, long) Method
Thread.VolatileWrite(System.SByte&, sbyte) Method
Thread.VolatileWrite(System.UInt16&, ushort) Method
Thread.VolatileWrite(System.UInt32&, uint) Method
Thread.VolatileWrite(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 Properties
Thread.CurrentThread Property
Thread.IsAlive Property
Thread.IsBackground Property
Thread.Name Property
Thread.Priority Property
Thread.ThreadState Property
public Thread(ThreadStart start);
Constructs and initializes a new instance of the Thread class.
- start
- A ThreadStart delegate that references the methods to be invoked when the new thread begins executing.
Exception Type Condition ArgumentNullException start is null
.
[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.
System.Threading.Thread Class, System.Threading Namespace
public void Abort(object stateInfo);
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.
- stateInfo
- A Object that contains application-specific information, such as state, which can be used by the thread being aborted.
Exception Type Condition SecurityException Caller does not have System.Security.Permissions.SecurityPermissionFlag.ControlThread security permission for this thread.
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) ().]
System.Threading.Thread Class, System.Threading Namespace
public void Abort();
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.
Exception Type Condition SecurityException Caller does not have System.Security.Permissions.SecurityPermissionFlag.ControlThread security permission for the thread to be aborted.
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:
- unmanaged code
- a catch handler
- a finally clause
- a filter clause
- a type initializer
Unexecuted
- 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
- 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).
- 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.
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 .]
System.Threading.Thread Class, System.Threading Namespace
~Thread();
Releases the resources held by this instance.
[Note: Application code does not call this method; it is automatically invoked during garbage collection.]
System.Threading.Thread Class, System.Threading Namespace
public static AppDomain GetDomain();
Returns an object representing the application domain in which the current thread is executing.
A AppDomain object that represents the current application domain.
RuntimeInfrastructure
System.Threading.Thread Class, System.Threading Namespace
public void Join();
Blocks the calling thread until the thread on which this method is invoked terminates.
Exception Type Condition ThreadStateException The caller attempted to join a thread that is in the System.Threading.ThreadState.Unstarted state.
[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.
System.Threading.Thread Class, System.Threading Namespace
public bool Join(int millisecondsTimeout);
Blocks the calling thread until the thread on which this method is invoked terminates or the specified time elapses.
- millisecondsTimeout
- A Int32 containing the number of milliseconds to wait for the thread to terminate.
true
if the thread has terminated;false
if the thread has not terminated after millisecondsTimeout has elapsed.
Exception Type Condition ArgumentOutOfRangeException The value of millisecondsTimeout is negative and is not equal to System.Threading.Timeout.Infinite . ThreadStateException The caller attempted to join a thread that is in the System.Threading.ThreadState.Unstarted state.
[Note: If System.Threading.Timeout.Infinite is specified for millisecondsTimeout, this method behaves identically toJoin
(), 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.
System.Threading.Thread Class, System.Threading Namespace
public bool Join(TimeSpan timeout);
Blocks the calling thread until the thread on which this method is invoked terminates or the specified time elapses.
- 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.
true
if the thread has terminated;false
if the thread has not terminated after the amount of time specified by timeout has elapsed.
Exception Type Condition ArgumentOutOfRangeException The value of timeout is negative and is not equal to System.Threading.Timeout.Infinite milliseconds, or is greater than System.Int32.MaxValue milliseconds. ThreadStateException The caller attempted to join a thread that is in the System.Threading.ThreadState.Unstarted state.
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.
System.Threading.Thread Class, System.Threading Namespace
public static void MemoryBarrier ();
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.
System.Threading.Thread Class, System.Threading Namespace
public static void ResetAbort();
Cancels a System.Threading.Thread.Abort(System.Object) requested for the current thread.
Exception Type Condition ThreadStateException System.Threading.Thread.Abort(System.Object) was not invoked on the current thread. SecurityException Caller does not have System.Security.Permissions.SecurityPermissionFlag.ControlThread security permission for the current thread.
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 theThreadAbortException
from terminating the thread.
For an example that demonstrates calling this method, see ThreadAbortException .
System.Threading.Thread Class, System.Threading Namespace
public static void Sleep(int millisecondsTimeout);
Blocks the current thread for the specified number of milliseconds.
- 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.
Exception Type Condition ArgumentOutOfRangeException The value of millisecondsTimeout is negative and is not equal to System.Threading.Timeout.Infinite .
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.
System.Threading.Thread Class, System.Threading Namespace
public static void Sleep(TimeSpan timeout);
Blocks the current thread for a specified time.
- 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.
Exception Type Condition ArgumentOutOfRangeException The value of timeout is negative and is not equal to System.Threading.Timeout.Infinite milliseconds, or is greater than System.Int32.MaxValue milliseconds.
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.
System.Threading.Thread Class, System.Threading Namespace
public void Start();
Causes the operating system to consider the thread ready to be scheduled for execution.
Exception Type Condition OutOfMemoryException There is not enough memory available to start the thread. NullReferenceException This method was invoked on a null
thread reference.ThreadStateException The thread has already been started.
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.
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.
Note that the sequence of the output statements is not guaranteed to be identical across systems.Working thread ...
In main.
Working thread ...
In main.
Working thread ...
System.Threading.Thread Class, System.Threading Namespace
public static byte VolatileRead (ref byte address);
Performs a volatile read from the specified address.
- address
- A Byte that specifies the address in memory from which to read.
A Byte containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static short VolatileRead (ref short address);
Performs a volatile read from the specified address.
- address
- A Int16 that specifies the address in memory from which to read.
A Int16 containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static int VolatileRead (ref int address);
Performs a volatile read from the specified address.
- address
- A Int32 that specifies the address in memory from which to read.
A Int32 containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static long VolatileRead (ref long address);
Performs a volatile read from the specified address.
- address
- A Int64 that specifies the address in memory from which to read.
A Int64 containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static sbyte VolatileRead (ref sbyte address);
Performs a volatile read from the specified address.
- address
- A SByte that specifies the address in memory from which to read.
A SByte containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static ushort VolatileRead (ref ushort address);
Performs a volatile read from the specified address.
- address
- A UInt16 that specifies the address in memory from which to read.
A UInt16 containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static uint VolatileRead (ref uint address);
Performs a volatile read from the specified address.
- address
- A UInt32 that specifies the address in memory from which to read.
A UInt32 containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static IntPtr VolatileRead (ref IntPtr address);
Performs a volatile read from the specified address.
- address
- A IntPtr that specifies the address in memory from which to read.
A IntPtr containing the value at the specified address after any pending writes.
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 IL 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.]
RuntimeInfrastructure
System.Threading.Thread Class, System.Threading Namespace
public static UIntPtr VolatileRead (ref UIntPtr address);
Performs a volatile read from the specified address.
- address
- A UIntPtr that specifies the address in memory from which to read.
A UIntPtr containing the value at the specified address after any pending writes.
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 IL 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.]
RuntimeInfrastructure
System.Threading.Thread Class, System.Threading Namespace
public static ulong VolatileRead (ref ulong address);
Performs a volatile read from the specified address.
- address
- A UInt64 that specifies the address in memory from which to read.
A UInt64 containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static float VolatileRead (ref float address);
Performs a volatile read from the specified address.
- address
- A Single that specifies the address in memory from which to read.
A Single containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static double VolatileRead (ref double address);
Performs a volatile read from the specified address.
- address
- A Double that specifies the address in memory from which to read.
A Double containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static object VolatileRead (ref object address);
Performs a volatile read from the specified address.
- address
- A Object that specifies the address in memory from which to read.
A Object containing the value at the specified address after any pending writes.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref byte address, byte value);
Performs a volatile write to the specified address.
- address
- A Byte that specifies the address in memory at which to write.
- value
- A Byte that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref short address, short value);
Performs a volatile write to the specified address.
- address
- A Int16 that specifies the address in memory at which to write.
- value
- A Int16 that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref int address, int value);
Performs a volatile write to the specified address.
- address
- A Int32 that specifies the address in memory at which to write.
- value
- A Int32 that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref long address, long value);
Performs a volatile write to the specified address.
- address
- A Int64 that specifies the address in memory at which to write.
- value
- A Int64 that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref sbyte address, sbyte value);
Performs a volatile write to the specified address.
- address
- A SByte that specifies the address in memory at which to write.
- value
- A SByte that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref ushort address, ushort value);
Performs a volatile write to the specified address.
- address
- A UInt16 that specifies the address in memory at which to write.
- value
- A UInt16 that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref uint address, uint value);
Performs a volatile write to the specified address.
- address
- A UInt32 that specifies the address in memory at which to write.
- value
- A UInt32 that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref ulong address, ulong value);
Performs a volatile write to the specified address.
- address
- A UInt64 that specifies the address in memory at which to write.
- value
- A UInt64 that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref UIntPtr address, UIntPtr value);
Performs a volatile write to the specified address.
- address
- A UIntPtr that specifies the address in memory at which to write.
- value
- A UIntPtr that specifies the value to write.
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 IL 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.]
RuntimeInfrastructure
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref IntPtr address, IntPtr value);
Performs a volatile write to the specified address.
- address
- A IntPtr that specifies the address in memory at which to write.
- value
- A IntPtr that specifies the value to write.
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 IL 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.]
RuntimeInfrastructure
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref float address, float value);
Performs a volatile write to the specified address.
- address
- A Single that specifies the address in memory at which to write.
- value
- A Single that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref double address, double value);
Performs a volatile write to the specified address.
- address
- A Double that specifies the address in memory at which to write.
- value
- A Double that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static void VolatileWrite (ref object address, object value);
Performs a volatile write to the specified address.
- address
- A Object that specifies the address in memory at which to write.
- value
- A Object that specifies the value to write.
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 IL 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.]
System.Threading.Thread Class, System.Threading Namespace
public static Thread CurrentThread { get; }
Gets a Thread instance that represents the currently executing thread.
An instance of Thread representing the current thread.
This property is read-only.
System.Threading.Thread Class, System.Threading Namespace
public bool IsAlive { get; }
Gets a Boolean value indicating the execution status of the current thread.
true
if this thread has been started, and has not terminated; otherwise,false
.
This property is read-only.This property returns true unless the System.Threading.Thread.ThreadState of the thread contains System.Threading.ThreadState.Unstarted, or System.Threading.ThreadState.Stopped.
System.Threading.Thread Class, System.Threading Namespace
public bool IsBackground { get; set; }
Gets or sets a Boolean value indicating whether a thread is a background thread.
true
if the thread is or is to become a background thread; otherwise,false
.
Exception Type Condition ThreadStateException The thread has reached the System.Threading.ThreadState.Stopped state.
The default value of this property isfalse
. 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. ]
System.Threading.Thread Class, System.Threading Namespace
public string Name { get; set; }
Gets or sets the name of the thread.
A String containing the name of the thread, ornull
if no name was set.
Exception Type Condition InvalidOperationException A set operation was requested, and the Name
property has already been set.
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.
System.Threading.Thread Class, System.Threading Namespace
public ThreadPriority Priority { get; set; }
Gets or sets a value indicating the scheduling priority of a thread.
A ThreadPriority value.
Exception Type Condition ThreadStateException The thread is in the System.Threading.ThreadState.Stopped state. ArgumentException The value specified for a set operation is not a valid ThreadPriority value.
A thread can be assigned any one of the following priority values:
The default value is System.Threading.ThreadPriority.Normal.
- System.Threading.ThreadPriority.Highest
- System.Threading.ThreadPriority.AboveNormal
- System.Threading.ThreadPriority.Normal
- System.Threading.ThreadPriority.BelowNormal
- System.Threading.ThreadPriority.Lowest
Operating systems are not required to honor the priority of a thread.
System.Threading.Thread Class, System.Threading Namespace
public ThreadState ThreadState { get; }
Gets a value containing the states of the current thread.
A combination of one or more ThreadState values, which indicate the state of the current thread.
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.
System.Threading.Thread Class, System.Threading Namespace