Exemple #1
0
        /// <summary>
        /// 监听用户关闭控制台应用程序
        /// </summary>
        /// <param name="shutDownConsoleFactory">委托</param>
        /// 时间:2016-05-23 13:09
        /// 备注:
        public static void DetectShutdown(Action shutDownConsoleFactory)
        {
            ConsoleCtrlHanlder _shutDownHanlder = new ConsoleCtrlHanlder(ctrlType =>
            {
                switch (ctrlType)
                {
                case CTRL_CLOSE_EVENT:
                    shutDownConsoleFactory();
                    break;
                }

                return(false);
            });

            SetConsoleCtrlHandler(_shutDownHanlder, true);
        }
Exemple #2
0
 private static extern bool SetConsoleCtrlHandler(ConsoleCtrlHanlder detectShutdown, bool Add);