private static bool DebugSwitch(string[] args) { switch (args.FirstOrDefault()) { case "run": using (DaemonWebServer server = new DaemonWebServer()) { server.Start(); Console.WriteLine("Application started."); Console.WriteLine("Press any key to stop the server"); try { ConsoleKeyInfo key; do { key = Console.ReadKey(true); } while (key.Key == 0 && key.KeyChar == '\0'); } catch (Exception) { try { while (true) { Thread.Sleep(int.MaxValue); } } catch (Exception ex) { Console.Error.WriteLine(ex); } } Console.WriteLine("Shutting down server..."); } break; default: return(false); } return(true); }
protected override void OnStop() { Server.Dispose(); Server = null; Instance = null; }
protected override void OnStart(string[] args) { Instance = this; Server = new DaemonWebServer(); Server.Start(); }