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...");
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIFJlY2V0YXMuQ1NoYXJwLkNhcDA0LlIwNDA4CnsKICAgIHB1YmxpYyBzZWFsZWQgY2xhc3MgVXNvRXZlbnRXYWl0SGFuZGxlCiAgICB7CiAgICAgICAgLy8gQ3JlYSBpbnN0YW5jaWEgZGUgRXZlbnRSZXNldEV2ZW50IHBhc2FuZG8gZmFsc2UgCiAgICAgICAgLy8gYWwgYXJndW1lbnRvLiBFc3RvIGV2aXRhIHF1ZSBhdXRvbcOhdGljYW1lbnRlIHNlIGludm9xdWUgCiAgICAgICAgLy8gZWwgbcOpdG9kbyBgU2V0YDoKICAgICAgICBzdGF0aWMgRXZlbnRXYWl0SGFuZGxlIHdhaXRIYW5kbGUgPSBuZXcgRXZlbnRXYWl0SGFuZGxlIChmYWxzZSwgRXZlbnRSZXNldE1vZGUuQXV0b1Jlc2V0KTsKICAgICAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBuZXcgVGhyZWFkIChQcm9jZXNvRXNwZXJhKS5TdGFydCAoKTsKICAgICAgICAgICAgVGhyZWFkLlNsZWVwICgxNTAwKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIEFjdGl2YSBsYSBzZcOxYWwgb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