articles

Home / DeveloperSection / Articles / Multithreading in c#

Multithreading in c#

Amit Singh6164 29-Sep-2010

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
{
    classProgram
    {
        staticvoid Main(string[] args)
        {
            Thread table2 = newThread(newThreadStart(tableA));
            Thread table3 = newThread(newThreadStart(tableB));         
            table2.Start();           
            table3.Start();           
            Console.Read();
        }
        publicstaticvoid tableA()
        {
            for (int i = 1; i < 11; i++)
                Console.WriteLine("2*" + i + " = " + 2 * 2000);
        }
        publicstaticvoid tableB()
        {
            for (int j = 1; j < 11; j++)
                Console.WriteLine("3*" + j + " = " + 3 * j);
        }
    }
 Output: 

Multithreading in c#

 You can also read these related post

https://www.mindstick.com/Articles/1488/multithreading-in-c-sharp




Updated 04-Mar-2020

Leave Comment

Comments

Liked By