Home > DeveloperSection > Articles > Multithreading in c#

Multithreading in c#


.NET .NET 
Ratings:
0 Comment(s)
 3676  View(s)
Rate this:

Multithreading in c#

Multithreading is a feature provided by the operating system that enables your application to have more than on execution path at the same time. We use the thread functionality in our project by using System.Threading namespace. A thread in .Net is represented by the System.Threading.Thred class. We can create multiple threads in our program by creating multiple instances (object) of this class. A thread starts its execution by calling the specific method and terminates when the execution of that method gets completed.

The most commonly used instance members of thread class are:

Member

Name

Priority

IsAlive

ThreadState

Start()

Abort()

Suspend()

Resume()

Join()

 

Example:

 

namespace Multithread

{

    class Program

    {

        static void Main(string[] args)

        {

            Thread table2 = new Thread(new ThreadStart(tableA));

            Thread table3 = new Thread(new ThreadStart(tableB));         

            table2.Start();           

            table3.Start();           

            Console.Read();

        }

        public static void tableA()

        {

            for (int i = 1; i < 11; i++)

                Console.WriteLine("2*" + i + " = " + 2 * 2000);

        }

        public static void tableB()

        {

            for (int j = 1; j < 11; j++)

                Console.WriteLine("3*" + j + " = " + 3 * j);

        }

    }

 

 

 

Output:

 

 


Don't want to miss updates? Please click the below button!

Follow MindStick