Multi-threading is the ability of CPU to execute small parts of a program (known as threads), simultaneously. Multitasking allows your program to perform more than one task at a time. It makes your program run faster.
What is a thread? Why should you use multithreading?
A thread is a light-weight process. Using multiple threads in your program can improve efficiency.
For every Windows application with a User Interface (UI), there will be
Multithreading in C#
In C#, System.Threading namespace comes with everything you need to create a multi-threaded application.
static void Main(string args)
ThreadStart t1 = new ThreadStart(Task1);
Thread t = new Thread(t1);
t.Name = "ChildThread1";
static void Task1()
Console.WriteLine("This is "+ Thread.CurrentThread.Name);
Console.WriteLine("Hello Thread 1");
This is ChildThread1
Hello Thread 1
Life cycle of a thread
The life cycle of a thread starts when an object of System.Threading.Thread is created and ends when a thread has completed its execution or is terminated.
Following is the states of a thread in its life cycle:
- Unstarted – A thread has not started its execution. An instance of Thread is created.
- Ready – The Start() method is called and the thread is ready to run.
- Running – The thread is being executed.
- Not running – The thread has temporarily stopped running.
- Dead state – The thread has completed its execution or is terminated.