System.Threading.Thread Class

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

See Also: Thread Members

Syntax

[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComDefaultInterface(typeof(System.Runtime.InteropServices._Thread))]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Thread : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, System.Runtime.InteropServices._Thread

Remarks

A process can create one or more threads to execute a portion of the program code associated with the process. Use a System.Threading.ThreadStart delegate or the System.Threading.ParameterizedThreadStart delegate to specify the program code executed by a thread. The System.Threading.ParameterizedThreadStart delegate allows you to pass data to the thread procedure.

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

object.GetHashCode provides identification for managed threads. For the lifetime of your thread, it will not collide with the value from any other thread, regardless of the application domain from which you obtain the value.

Note:

An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host can use the CLR Hosting API to schedule many managed threads against the same operating system thread, or to move a managed thread between different operating system threads.

It is not necessary to retain a reference to a System.Threading.Thread object once you have started the thread. The thread continues to execute until the thread procedure is complete.

Note:

Beginning with the net_v40_long, the behavior of some thread constructors is changed: Only fully trusted code can set the maximum stack size to a value that is greater than the default stack size (1 megabyte). If a larger value is specified when code is running with partial trust, the larger value is ignored and the default stack size is used. No exception is thrown. Code at any trust level can set the maximum stack size to a value that is less than the default stack size.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0