C# Thread Life Cycle
A thread in C# has a life cycle, which starts when the instance of the System.Threading.Thread class is created, and it ends when the task execution of the thread is completed. In C#, the life cycle of a thread has the following states:
- Unstarted
- Runnable (Ready to run)
- Running
- Not Runnable
- Dead (Terminated)
Unstarted State:
A thread in C# is in the unstarted state by default, when the instance of the Thread class is created.
Runnable State:
A thread in C# is in the ready-to-run state or in the runnable state when the start() method on the thread is called.
Running State:
A thread in C# is in the running state at the time of execution. At a time within a process, only one thread can be executed.
Not Runnable State:
A thread in C# is in the not runnable state, when the input/output operation is blocked or when the sleep() or wait() method is called on the thread.
Dead State:
A thread in C# enters into the dead or terminated state, after completing a task.