C# Thread Join
To instruct the calling threads to wait until the current thread or the joined thread is terminated or completes the specified task, the join() method is used in C#.
Example:
using System; using System.Threading; public class Example { public void thrd1() { for (char i = 'a'; i < 'g'; i++) { Console.WriteLine(i); Thread.Sleep(100); } } } public class thrd2 { public static void Main() { Example thrd = new Example(); Thread x = new Thread(new ThreadStart(thrd.thrd1)); Thread y = new Thread(new ThreadStart(thrd.thrd1)); Thread z = new Thread(new ThreadStart(thrd.thrd1)); x.Start(); x.Join(); y.Start(); z.Start(); } } |
Output:
Explanation:
In the above example, we are displaying the use and behavior of the Join() method in C#.