EN
C#/.NET - sleep thread
10
points
To pause thread in C#/.NET Thread.Sleep
method can be used.
using System;
using System.Threading;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Thread thread = new Thread(() =>
{
Console.WriteLine("My thread: step 1");
Thread.Sleep(1000);
Console.WriteLine("My thread: step 2");
Thread.Sleep(1000);
Console.WriteLine("My thread: step 3");
});
thread.Start();
Console.WriteLine("Main thread: step 1");
Thread.Sleep(1000);
Console.WriteLine("Main thread: step 2");
Thread.Sleep(1000);
Console.WriteLine("Main thread: step 3");
}
}
}
Output:
Main thread: step 1
My thread: step 1
Main thread: step 2
My thread: step 2
Main thread: step 3
My thread: step 3
Note: Thread.Sleep sleeps thread in which method has been called for some milliseconds.