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.
Thread.Join
method example.
using System;
using System.Threading;
namespace Test
{
class Program
{
static void Main(string[] args)
{
Thread thread = new Thread(() =>
{
Console.WriteLine("Thread before sleeping...");
Thread.Sleep(2000);
Console.WriteLine("Thread after sleeping...");
});
thread.Start();
Console.WriteLine("Before waiting...");
thread.Join();
Console.WriteLine("After waiting...");
}
}
}
Where:
Thread.Join
method - sleeps current code until executed thread will not finish working
Output:
Thread before sleeping...
Before waiting...
Thread after sleeping...
After waiting...