Created
July 16, 2014 17:40
-
-
Save Fhernd/b9bfa0b50b79eb3beaad to your computer and use it in GitHub Desktop.
Demostración del uso de la clase AutoResetEvent para la sincronización basada en eventos.
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 UsoAutoResetEvent | |
{ | |
// Crea instancia de EventResetEvent pasando false | |
// al argumento. Esto evita que automáticamente se invoque | |
// el método `Set`: | |
static EventWaitHandle waitHandle = new AutoResetEvent (false); | |
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