示例#1
0
        internal static void executeServiceAsConsole()
        {
            NativeMethods.AllocConsole();
            service = new OpenVPNserviceRunner();
            _handler += new NativeMethods.HandlerRoutine(ConsoleCtrlCheck);
            NativeMethods.SetConsoleCtrlHandler(_handler, true);// Allow console to properly take shutdown also on Ctrl+C or closing the Console window.

            service.StartAsConsole();
            try
            {
                string input = string.Empty;
                Console.WriteLine("\r\nType \"exit\" and press Enter to stop.");
                while (input != null && input.ToLower() != "exit")
                    input = Console.ReadLine();
                service.Shutdown();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        internal static void executeServiceAsConsole()
        {
            NativeMethods.AllocConsole();
            service   = new OpenVPNserviceRunner();
            _handler += new NativeMethods.HandlerRoutine(ConsoleCtrlCheck);
            NativeMethods.SetConsoleCtrlHandler(_handler, true);// Allow console to properly take shutdown also on Ctrl+C or closing the Console window.

            service.StartAsConsole();
            try
            {
                string input = string.Empty;
                Console.WriteLine("\r\nType \"exit\" and press Enter to stop.");
                while (input != null && input.ToLower() != "exit")
                {
                    input = Console.ReadLine();
                }
                service.Shutdown();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
 private static bool ConsoleCtrlCheck(NativeMethods.CtrlTypes ctrlType)
 {
     service.Shutdown();
     return(true);
 }