EN
C#/.NET - thread join
3 points
In C#/.NET it is possible to wait with Thread.Join
method until some thread will not finish working.
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("Thread before sleeping...");
13
Thread.Sleep(2000);
14
Console.WriteLine("Thread after sleeping...");
15
});
16
17
thread.Start();
18
Console.WriteLine("Before waiting...");
19
thread.Join();
20
Console.WriteLine("After waiting...");
21
}
22
}
23
}
Where:
Thread.Join
method - sleeps current code until executed thread will not finish working
Output:
xxxxxxxxxx
1
Thread before sleeping...
2
Before waiting...
3
Thread after sleeping...
4
After waiting...