Threading in C#

Threading in C#

Threading can boost the performance of application if used wisely. In this tutorial I will show you how to create thread in C#.net. This is very simple application for beginners. System.Threading is the namespace used for Type thread in C#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ConsoleDemo.App
{
    class Program
    {
        static void Main(string[] args)
        {

            Thread t1 = new Thread( MethodA );
            t1.Start();
            Console.WriteLine("This is main thread.");
            t1.Join();
            Console.ReadLine();

        }

        static void MethodA()
        {
            Thread.Sleep(1000);
            Console.WriteLine("Thread Method A");
        }
        
    }
}

Output of Simple Threading application in C#

This is main thread.
Thread Method A

The program creates simple tread in C#. Instance of Thread accepts method to execute when thread start. Join method of thread instance blocks exit of main thread till thread t1 get finished.

C# foreach loopc# arraylistc# stringC# DateTime DifferenceC# XML XmlReaderC# Binary To StringC# Regular Expression Get Text Between BracketsC# For LoopReplace string in C#C# DateTimeC# while loop

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.