Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

C#/.NET - thread join

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

References

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

See also

  1. C#/.NET - create thread
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more