Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. public class Example
  5. {
  6. static Thread thread1, thread2;
  7.  
  8. public static void Main()
  9. {
  10. thread1 = new Thread(ThreadProc);
  11. thread1.Name = "Thread1";
  12. thread1.Start();
  13.  
  14. thread2 = new Thread(ThreadProc);
  15. thread2.Name = "Thread2";
  16. thread2.Start();
  17. }
  18.  
  19. private static void ThreadProc()
  20. {
  21. Console.WriteLine("nCurrent thread: {0}", Thread.CurrentThread.Name);
  22. if (Thread.CurrentThread.Name == "Thread1" &&
  23. thread2.ThreadState != ThreadState.Unstarted)
  24. thread2.Join();
  25.  
  26. Thread.Sleep(4000);
  27. Console.WriteLine("nCurrent thread: {0}", Thread.CurrentThread.Name);
  28. Console.WriteLine("Thread1: {0}", thread1.ThreadState);
  29. Console.WriteLine("Thread2: {0}n", thread2.ThreadState);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement