Threading in C#

Threading enables C# program to perform concurrent processing so that you can do more than one operation at a time. 

In order to create threading in C#, we need to import threading namespace i.e. System.Threading. Using this namespace we can create thread object which can help us to create thread applications.

For creating threading application, there some important methods which used regularly for implementing threading.
1 : Thread Join
2 : Thread Sleep
3 : Thread Abort

Thread Join
Thread.Join() make thread to finish its work or makes other thread to halt until it finishes work. Join method when attached to any thread, it makes that thread to execute first and halts other threads.

Thread Sleep
Thread.Sleep a method used to suspend current thread for a specific interval of time. Time can be specified in milliseconds or Timespan.

Thread Abort
As name implies "Abort" so same way Thread.Abort helps to end or abort any thread to process it further. It raises ThreadAbortException in the thread for process of termination.


Types of Threads in C#
There are two types of Thread in Csharp i.e. Foreground Thread and Background Thread.
1)  Foreground threads are those threads which keeps running until it finishes his work even if the Main method thread quits its process. Lifespan of foreground threads does not depends on main thread.
2)  Background thread is just opposite of foreground thread here background thread quits its job when main thread quits. Lifespan of background threads depends on main thread. In order to implement background thread in a program we need to set property called IsBackground to true.