Upraviť

Zdieľať cez


Thread Class

Definition

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

public ref class Thread sealed : System::Runtime::ConstrainedExecution::CriticalFinalizerObject
public ref class Thread sealed
public ref class Thread sealed : System::Runtime::InteropServices::_Thread
public ref class Thread sealed : System::Runtime::ConstrainedExecution::CriticalFinalizerObject, System::Runtime::InteropServices::_Thread
public sealed class Thread : System.Runtime.ConstrainedExecution.CriticalFinalizerObject
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Thread
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class Thread : System.Runtime.InteropServices._Thread
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class Thread : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, System.Runtime.InteropServices._Thread
type Thread = class
    inherit CriticalFinalizerObject
[<System.Runtime.InteropServices.ComVisible(true)>]
type Thread = class
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type Thread = class
    interface _Thread
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type Thread = class
    inherit CriticalFinalizerObject
    interface _Thread
Public NotInheritable Class Thread
Inherits CriticalFinalizerObject
Public NotInheritable Class Thread
Public NotInheritable Class Thread
Implements _Thread
Public NotInheritable Class Thread
Inherits CriticalFinalizerObject
Implements _Thread
Inheritance
Inheritance
Thread
Attributes
Implements

Remarks

For more information about this API, see Supplemental API remarks for Thread.

Constructors

Thread(ParameterizedThreadStart, Int32)

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

Thread(ParameterizedThreadStart)

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

Thread(ThreadStart, Int32)

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

Thread(ThreadStart)

Initializes a new instance of the Thread class.

Properties

ApartmentState
Obsolete.
Obsolete.

Gets or sets the apartment state of this thread.

CurrentContext

Gets the current context in which the thread is executing.

CurrentCulture

Gets or sets the culture for the current thread.

CurrentPrincipal

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

CurrentThread

Gets the currently running thread.

CurrentUICulture

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

ExecutionContext

Gets an ExecutionContext object that contains information about the various contexts of the current thread.

IsAlive

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

IsBackground

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

IsThreadPoolThread

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

ManagedThreadId

Gets a unique identifier for the current managed thread.

Name

Gets or sets the name of the thread.

Priority

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

ThreadState

Gets a value containing the states of the current thread.

Methods

Abort()
Obsolete.

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

Abort(Object)
Obsolete.

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

AllocateDataSlot()

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

AllocateNamedDataSlot(String)

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

BeginCriticalRegion()

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

BeginThreadAffinity()

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

DisableComObjectEagerCleanup()

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

EndCriticalRegion()

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

EndThreadAffinity()

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

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize()

Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the Thread object.

FreeNamedDataSlot(String)

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

GetApartmentState()

Returns an ApartmentState value indicating the apartment state.

GetCompressedStack()
Obsolete.
Obsolete.

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

GetCurrentProcessorId()

Gets an ID used to indicate on which processor the current thread is executing.

GetData(LocalDataStoreSlot)

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

GetDomain()

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

GetDomainID()

Returns a unique application domain identifier.

GetHashCode()

Returns a hash code for the current thread.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetNamedDataSlot(String)

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

GetType()

Gets the Type of the current instance.

(Inherited from Object)
Interrupt()

Interrupts a thread that is in the WaitSleepJoin thread state.

Join()

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

Join(Int32)

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

Join(TimeSpan)

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

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemoryBarrier()

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

ResetAbort()
Obsolete.

Cancels an Abort(Object) requested for the current thread.

Resume()
Obsolete.
Obsolete.
Obsolete.

Resumes a thread that has been suspended.

SetApartmentState(ApartmentState)

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

SetCompressedStack(CompressedStack)
Obsolete.
Obsolete.

Applies a captured CompressedStack to the current thread.

SetData(LocalDataStoreSlot, Object)

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

Sleep(Int32)

Suspends the current thread for the specified number of milliseconds.

Sleep(TimeSpan)

Suspends the current thread for the specified amount of time.

SpinWait(Int32)

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

Start()

Causes the operating system to change the state of the current instance to Running.

Start(Object)

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

Suspend()
Obsolete.
Obsolete.
Obsolete.

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

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TrySetApartmentState(ApartmentState)

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

UnsafeStart()

Causes the operating system to change the state of the current instance to Running.

UnsafeStart(Object)

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

VolatileRead(Byte)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(Double)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(Int16)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(Int32)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(Int64)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(IntPtr)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(Object)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(SByte)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(Single)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(UInt16)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(UInt32)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(UInt64)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileRead(UIntPtr)
Obsolete.

Reads the value of a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears after this method in the code, the processor cannot move it before this method.

VolatileWrite(Byte, Byte)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(Double, Double)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(Int16, Int16)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(Int32, Int32)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(Int64, Int64)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(IntPtr, IntPtr)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(Object, Object)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(SByte, SByte)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(Single, Single)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(UInt16, UInt16)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(UInt32, UInt32)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(UInt64, UInt64)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

VolatileWrite(UIntPtr, UIntPtr)
Obsolete.

Writes a value to a field. On systems that require it, inserts a memory barrier that prevents the processor from reordering memory operations as follows: If a read or write appears before this method in the code, the processor cannot move it after this method.

Yield()

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

Explicit Interface Implementations

_Thread.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.

_Thread.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can then be used to get the type information for an interface.

_Thread.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

_Thread.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.

Applies to

Thread Safety

This type is thread safe.

See also