Delivering Measurable Online Success

Basic understanding of Multithreading in .Net Applications

June 30, 2009 – 10:38 pm

Multithreading is a powerful tool for creating high performance applications, especially those that require user interaction. Microsoft .NET has broken down the barriers that once existed in creating multithreaded applications. 

Newer operating systems, such as Windows 2000, support pre-emptive multitasking, which allocates each thread a time slice. When the time slice of the currently executing thread has elapsed, the thread is suspended by the operating system, context of the thread is saved, context of another thread is loaded, and the other thread then resumes execution according to its previous state. This gives the appearance that multiple threads are executing at the same time and helps prevent the system from becoming unresponsive from a single thread. On systems that have more that one-processor threads are distributed across all of the processors so there really are multiple threads executing at the same time. 

.NET has been designed to support multi-threaded operation. There are two main ways of multi-threading in .NET: -

  1. Thread class
  2. Thread pool

Every thread has a priority. You can assign different priorities to the threads in application. That means you can tell the system which thread can be done first, which thread can interrupt others and which thread cannot be interrupted. Each thread with the highest priority can interrupt a thread with a lower priority. Below are values for thread priority -

  1. Highest
  2. AboveNormal
  3. Normal
  4. BelowNormal
  5. Lowest

A thread can be stopped for a given period of time. To make a thread stop you can use sleep method with number of milliseconds to sleep. The thread will resume after the specified milliseconds.

We can stop a thread by using suspend() method. This way thread will wait until you call it back to action. To call a thread back to action you can use resume() method.

We can stop or abort a thread at any time by using abort() method. This will destroy all the data related to that thread.

.Net makes it easy to add multithreading to your application. By this you can make the application more interactive and can increase the user’s experience.

Happy Programming!

  1. One Response to “Basic understanding of Multithreading in .Net Applications”

  2. Thanks! This blog proves helpful for the .NET developers in a simple & clear way. one can easily understand the working of the Multi-Threading in .Net application.
    Very great topic…too advanced yet too clear.

    By Sunny on Jul 7, 2009

Post a Comment

*Please fill correct value in the text box given below.