using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
public class MainClass
{
public static void Main()
{
using (EventWaitHandle ewh = new ManualResetEvent(false))
using (EventWaitHandle callbackDoneEvent = new ManualResetEvent(false))
{
ThreadPool.RegisterWaitForSingleObject(ewh,
delegate {
Console.WriteLine("Callback fired: {0}", Thread.CurrentThread.ManagedThreadId);
callbackDoneEvent.Set();
}, null, Timeout.Infinite, true);
Console.WriteLine("Setting the event: {0}", Thread.CurrentThread.ManagedThreadId);
ewh.Set();
callbackDoneEvent.WaitOne();
}
}
}