Methods of the Thread Class

CsharpProgrammingServer Side Programming

Some of the popular methods of a Thread class is start, sleep, jon, and abort. Let us see the complete list of methods −

Sr.No. Method & Description
1

public void Abort()

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.

2

public static LocalDataStoreSlot AllocateDataSlot()

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

3

public static LocalDataStoreSlot AllocateNamedDataSlot(string name)

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

4

public static void BeginCriticalRegion()

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

5

public static void BeginThreadAffinity()

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

6

public static void EndCriticalRegion()

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

7

public static void EndThreadAffinity()

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

8

public static void FreeNamedDataSlot(string name)

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

9

public static Object GetData(LocalDataStoreSlot slot)

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

10

public static AppDomain GetDomain()

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

11

public static AppDomain GetDomainID()

Returns a unique application domain identifier

12

public static LocalDataStoreSlot GetNamedDataSlot(string name)

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

13

public void Interrupt()

Interrupts a thread that is in the WaitSleepJoin thread state.

14

public void Join()

Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping. This method has different overloaded forms.

15

public static void MemoryBarrier()

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

16

public static void ResetAbort()

Cancels an Abort requested for the current thread.

17

public static void SetData(LocalDataStoreSlot slot, Object data)

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

18

public void Start()

Starts a thread.

19

public static void Sleep(int millisecondsTimeout)

Makes the thread pause for a period of time.

20

public static void SpinWait(int iterations)

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

raja
Published on 16-Aug-2018 11:12:36
Advertisements