To pause a thread in C#, use the sleep() method.
You need to set the milliseconds for which you want the thread to pause, for example, for 5 seconds, use −
Thread.Sleep(5000);
Example
Let us see how to loop through and set the sleep method to pause the thread.
using System;
using System.Threading;
namespace Sample {
class Demo {
static void Main(string[] args) {
for (int i = 0; i < 10; i++) {
Console.WriteLine("Sleep for 1 second!");
Thread.Sleep(1000);
}
Console.ReadLine();
}
}
}Output
Sleep for 1 second! Sleep for 1 second! Sleep for 1 second! Sleep for 1 second! Sleep for 1 second! Sleep for 1 second! Sleep for 1 second! Sleep for 1 second! Sleep for 1 second! Sleep for 1 second!