EN
C#/.NET - sleep thread
10 points
xxxxxxxxxx
1
using System;
2
using System.Threading;
3
4
namespace Test
5
{
6
class Program
7
{
8
static void Main(string[] args)
9
{
10
Thread thread = new Thread(() =>
11
{
12
Console.WriteLine("My thread: step 1");
13
Thread.Sleep(1000);
14
Console.WriteLine("My thread: step 2");
15
Thread.Sleep(1000);
16
Console.WriteLine("My thread: step 3");
17
});
18
19
thread.Start();
20
21
Console.WriteLine("Main thread: step 1");
22
Thread.Sleep(1000);
23
Console.WriteLine("Main thread: step 2");
24
Thread.Sleep(1000);
25
Console.WriteLine("Main thread: step 3");
26
}
27
}
28
}
Output:
xxxxxxxxxx
1
Main thread: step 1
2
My thread: step 1
3
Main thread: step 2
4
My thread: step 2
5
Main thread: step 3
6
My thread: step 3
Note: Thread.Sleep sleeps thread in which method has been called for some milliseconds.