Threading
A thread is defined as the execution path of a program. Each thread defines a unique flow of control. If your application involves complicated and time-consuming operations, then it is often helpful to set different execution paths or threads, with each thread performing a particular job.
Threads are lightweight processes. One common example of the use of thread is the implementation of concurrent programming by modern operating systems. The use of threads saves wastage of the CPU cycle and increase the efficiency of an application.
So far we wrote the programs where a single thread runs as a single process which is the running instance of the application. However, this way the application can perform one job at a time. To make it execute more than one task at a time, it could be divided into smaller threads.
Thread Life Cycle
The life cycle of a thread starts when an object of the System.Threading.Thread class is created and ends when the thread is terminated or completes execution.
Following are the various stages in the life cycle of a thread ?
The Unstarted State ? It is the situation when the instance of the thread is created but the Start method is not called.
The Ready State ? It is the situation when the thread is ready to run and waiting CPU cycle.
The Not Runnable State ? A thread is not executable, when
- Sleep method has been called
- Wait method has been called
- Blocked by I/O operations
The Dead State ? It is the situation when the thread completes execution or is aborted.
Application Support Lead at eBSEG
4 年congratulations