Creating a Thread in C# :



To understand how to create a new C# program and use threads in it, perform the following steps :

1. Start Visual Studio 2013. Create a new C# Console Application project.

2. Make sure that the project uses .Net Framework 4.0 or higher version.

3. In the Program.cs file add the following using directive:


using System;;
using System.Threading;

4. Add the following code snippet below the Main method:

static void PrintNumbers()
{
Console.WriteLine("Starting....");
for{int i=1; i<10; i++)
{
console.writeline(i);
}
}

5. Add the following code snippet inside the Main methods:

Thread t = new Thread(PrintNumbers);
t.Start();
PrintNumbers();

6. Run the program.