Example #1
0
        private static bool CloseConsoleHandler(CtrlType sig)
        {
            switch (sig)
            {
            case CtrlType.CTRL_C_EVENT:
            case CtrlType.CTRL_LOGOFF_EVENT:
            case CtrlType.CTRL_SHUTDOWN_EVENT:
            case CtrlType.CTRL_CLOSE_EVENT:
                try
                {
                    UnmanagedCPP.STOP();
                    exitFlag = true;
                } catch (Exception) { }
                break;

            default:
                return(false);
            }
            return(true);
        }
Example #2
0
        static void Main(string[] args)
        {
            closeConsoleHandler += new EventHandler(CloseConsoleHandler);
            SetConsoleCtrlHandler(closeConsoleHandler, true);

            Console.Out.WriteLine("Please type \"quit\" to quit this program!");
            try
            {
                UnmanagedCPP.CallBack callback = CallBackProc;
                UnmanagedCPP.INIT(callback);
                string strInput = Console.In.ReadLine();
                while (exitFlag == false && string.Compare(strInput, "quit", true) != 0)
                {
                    strInput = Console.In.ReadLine();
                    System.Threading.Thread.Sleep(10);
                }
                UnmanagedCPP.STOP();
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine("Error : {0}", ex.Message);
            }
        }