xxxxxxxxxx
int sleepTime = 1000; // in mills
Task.Delay(sleepTime).Wait();
// or
Thread.Sleep(sleepTime);
xxxxxxxxxx
// Thread Sleep vs Task Delay
int delayInSec = 3;
// Using Thread Sleep
Thread.Sleep(delayInSec * 1000);
// Using Task Delay
Task.Delay(delayInSec * 1000).Wait();
xxxxxxxxxx
using System;
using System.Threading;
class Program
{
static void Main()
{
Console.WriteLine("Program started.");
// Delay for 1 second (1000 milliseconds)
Thread.Sleep(1000);
Console.WriteLine("Delay completed. Program resumed.");
}
}