Advertisement
ivandrofly

Signaling with Event Wait Handles - C#

Mar 8th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Signaling_with_Event_Wait_Handles
  5. {
  6.     internal class Program
  7.     {
  8.         private static EventWaitHandle handle = new ManualResetEvent(false);
  9.  
  10.         private static void Main()
  11.         {
  12.             handle.Set();
  13.             new Thread(SayHello).Start("Holla");
  14.             new Thread(SayHello).Start("hello");
  15.             new Thread(SayHello).Start("hi");
  16.             new Thread(SayHello).Start("hey");
  17.             new Thread(SayHello).Start("ivandro");
  18.             new Thread(SayHello).Start("ismael");
  19.             new Thread(SayHello).Start("gomes jao");
  20.  
  21.             Thread.Sleep(2000);
  22.             handle.Reset();
  23.             new Thread(SayHello).Start("bonjour!");
  24.             Thread.Sleep(4000);
  25.             Thread.Sleep(4000);
  26.             handle.Set();
  27.         }
  28.  
  29.         private static void SayHello(object obj)
  30.         {
  31.             Console.WriteLine("Inside Sayhello data = " + obj);
  32.             handle.WaitOne();
  33.             Console.WriteLine(obj);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement