public void StartAsConsoleService() { Console.CancelKeyPress += (s, e) => { e.Cancel = true; _resetEvent.Set(); }; _daemon.Start(); _resetEvent.WaitOne(); _daemon.Stop(); }
protected override void OnStart(string[] args) { base.OnStart(args); OnEvent(Starting, new WindowsServiceEventArgs(ServiceName)); try { _daemon.Start(); } catch (Exception e) { OnEvent(Error, new ErrorEventArgs(new DaemonException(String.Format("Error starting service '{0}'.", ServiceName), e))); throw; } OnEvent(Started, new WindowsServiceEventArgs(ServiceName)); }