Created
July 16, 2014 18:32
-
-
Save Fhernd/385a1f939df153601772 to your computer and use it in GitHub Desktop.
Demostración del uso de la clase EventWaitHandle en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
namespace Recetas.CSharp.Cap04.R0408 | |
{ | |
public sealed class UsoEventWaitHandle | |
{ | |
// Crea instancia de EventResetEvent pasando false | |
// al argumento. Esto evita que automáticamente se invoque | |
// el método `Set`: | |
static EventWaitHandle waitHandle = new EventWaitHandle (false, EventResetMode.AutoReset); | |
public static void Main() | |
{ | |
new Thread (ProcesoEspera).Start (); | |
Thread.Sleep (1500); | |
// Activa la señal o notificación: | |
waitHandle.Set(); | |
} | |
static void ProcesoEspera() | |
{ | |
Console.WriteLine ("\nMétodo `ProcesoEspera` en espera..."); | |
waitHandle.WaitOne(); // A espera de notificación | |
Console.WriteLine ("Método `ProcesoEspera` notificado..."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment