Thread.Sleep(1000 * n);
Неблокирующее ожидание: await Task.Delay(1000 * n);
using System.Threading;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
Thread.Sleep(2000); // Приостанавливает программу на 2000 миллисекунд (или 2 секунды)
Console.WriteLine("Goodbye, World!");
}
}
public static void DelayAction(int _DelayMs, Action _Action)
{
Thread T = new Thread(() => { Thread.Sleep(_DelayMs); _Action.Invoke(); });
T.Start();
}
static void Main(string[] args)
{
int x = 8;
DelayAction(1000, () => x = 10);
Console.WriteLine(x);
Thread.Sleep(2000);
Console.WriteLine(x);
}