Pausing a Thread in C# :



To make a thread wait for some time without wasting operating system resources.

To understand how to pause a thread 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);
}
}


static void PrintNumbersWithDelay()
{
Console.WriteLine("Starting....");
for{int i=1; i<10; i++)
{
Thread.Sleep(TimeSpan.FromSeconds(2));
Console.WriteLine(1);
}
}

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

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

6. Run the program.