Thread Life Cycle in ASP .NET
Thread Life Cycle:
Creating: In this step, it is required for creating a thread which is created an object of System.Threading
.
Executing: After creating a thread Start() method of class System.Threading. A thread is used to execute a thread without waiting for another thread to complete.
Pausing: We use Thread.Sleep
method to pause a running thread for a specified time.
Cancelling: We need to cancel running thread, we use System.Threading. Abort() method to cancel a running thread.
Methods for Thread Class:
1. Start(): It is used to start a thread.
2. Sleep(): It is used to pause a running thread for a specified time.
3. Abort(): It is used to stop a thread when it is at a safe point.
4. Suspend(): It is used to restart a suspended thread.
5. Join(): It is used to bring the current thread to the waiting position until the previously started thread is completed.
Synchronization of Threads:
Synchronization provides a compromise between the unstructured nature of multithreaded programming and the structured order of synchronous processing. The Synchronization of Thread techniques is given as below:
- To explicitly control the order in which code runs whenever tasks must be performed in a specific sequence.
- To prevent the problems that can occur when two threads share the same resources at the same time.