Languages
[Edit]
EN

C#/.NET - thread join

3 points
Created by:
Wade
562

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...

References

  1. Thread Class - Microsoft Docs
  2. Thread.Join method - Microsoft Docs

See also

  1. C#/.NET - create thread
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# - Thread Class

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join