static bool ConsoleEventCallback(int eventType)
 {
     if (eventType == 2)
     {
         Console.WriteLine("Console window closing, death imminent");
         KeyboardRunner.Stop();
     }
     return(false);
 }
        static void Main(string[] args)
        {
            _mHandler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(_mHandler, true);

            KeyboardRunner.Start();
            ThreadStart ts     = new ThreadStart(KeyboardRunner.Update);
            Thread      thread = new Thread(ts);

            thread.Start();
            Console.WriteLine("Press ENTER to exit.");
            Console.ReadLine();
            KeyboardRunner.Stop();
        }