Users Pricing

articles

home / developersection / articles / multithreading

Multithreading

Uttam Misra 7090 15 Jul 2010 Updated 04 Mar 2020

In C# multithreading is a way to implement multitasking.

Example

 

  for (int i = 1; i <= 5;i++)
    {
//creating thread for display() method
      Thread t = new Thread(new ThreadStart(display));
//starting thread.
      t.Start();
    }  
 
   int i =0;
       
  public void display()
   {
    i++;
//displaying messagebox.
    MessageBox.Show(i.ToString());           
   }

 Screen Shot

Multithreading

 

Here we can see that all five message boxes are displayed. But if we had not used


threading then only one message box will be displayed and second box will be


displayed only after clicking on OK button of first Message Box. All five message


boxes are displayed simultaneously as different thread are created for display()


method called from loop.

 


Uttam Misra

Information Technology

More than 18 years of working experience in IT sector. We are here to serve you best.


1 Comments