public static void ExecuteServiceAsConsole() { NativeMethods.AllocConsole(); service = new OpenVPNServiceRunner(); _handler += new NativeMethods.HandlerRoutine(ConsoleCtrlCheck); // Allow console to properly take shutdown also on Ctrl+C or closing the Console window. NativeMethods.SetConsoleCtrlHandler(_handler, true); 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()); } }
public static IDisposable SetHandler(Func <CtrlTypes, bool> Action) { var HandlerRoutine = new NativeMethods.HandlerRoutine(Action); var result = NativeMethods.SetConsoleCtrlHandler(HandlerRoutine, true); if (!result) { return(null); } return(Disposable.Create(() => NativeMethods.SetConsoleCtrlHandler(HandlerRoutine, false))); }
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()); } }
public BreakerImpl() { NativeMethods.HandlerRoutine handerRoutine = new NativeMethods.HandlerRoutine(OnBreakReceived); GC.KeepAlive(handerRoutine); NativeMethods.SetConsoleCtrlHandler(handerRoutine, true); }
protected SetConsoleCtrl(Func <CtrlTypes, bool> ConsoleCtrl) { this.ConsoleCtrl = new NativeMethods.HandlerRoutine(ConsoleCtrl); NativeMethods.SetConsoleCtrlHandler(this.ConsoleCtrl, true); }