Advertisement
Fhernd

UsoEventWaitHandle.cs

Jul 16th, 2014
1,515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Recetas.CSharp.Cap04.R0408
  5. {
  6.     public sealed class UsoEventWaitHandle
  7.     {
  8.         // Crea instancia de EventResetEvent pasando false
  9.         // al argumento. Esto evita que automáticamente se invoque
  10.         // el método `Set`:
  11.         static EventWaitHandle waitHandle = new EventWaitHandle (false, EventResetMode.AutoReset);
  12.        
  13.         public static void Main()
  14.         {
  15.             new Thread (ProcesoEspera).Start ();
  16.             Thread.Sleep (1500);
  17.            
  18.             // Activa la señal o notificación:
  19.             waitHandle.Set();
  20.         }
  21.        
  22.         static void ProcesoEspera()
  23.         {
  24.             Console.WriteLine ("\nMétodo `ProcesoEspera` en espera...");
  25.             waitHandle.WaitOne();    // A espera de notificación
  26.             Console.WriteLine ("Método `ProcesoEspera` notificado...");
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement