Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- public class Program
- {
- static Thread thread1, thread2;
- public static void Main()
- {
- thread1 = new Thread(ThreadProc);
- thread1.Name = "ThreadMain";
- thread1.Start();
- thread2 = new Thread(ThreadProcHello);
- thread2.Name = "ThreadHello";
- thread2.Start();
- Console.ReadLine();
- }
- private static void ThreadProc()
- {
- if (Thread.CurrentThread.Name == "ThreadMain" && thread2.ThreadState != ThreadState.Unstarted)
- {
- Console.WriteLine("Thread: {0} joined", thread1.Name);
- thread2.Join();
- }
- Console.WriteLine("\nCurrent thread: {0}", Thread.CurrentThread.Name);
- Console.WriteLine("Thread1: {0}", thread1.ThreadState);
- Console.WriteLine("Thread2: {0}\n", thread2.ThreadState);
- int i = 0;
- while (i++ < 3)
- {
- Thread.Sleep(1000);
- Console.Out.Write("> ");
- }
- }
- private static void ThreadProcHello()
- {
- Console.WriteLine("HELLO WORLD!");
- Console.WriteLine("\nCurrent thread: {0}", Thread.CurrentThread.Name);
- Console.WriteLine("Thread1: {0}", thread1.ThreadState);
- Console.WriteLine("Thread2: {0}\n", thread2.ThreadState);
- int k = 0;
- while (k++ < 3)
- {
- Thread.Sleep(1000);
- Console.Out.Write("> ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement