Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 16, 2014 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/b9bfa0b50b79eb3beaad to your computer and use it in GitHub Desktop.
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.
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