示例#1
0
 public void StartAsConsoleService()
 {
     Console.CancelKeyPress += (s, e) => { e.Cancel = true; _resetEvent.Set(); };
     _daemon.Start();
     _resetEvent.WaitOne();
     _daemon.Stop();
 }
示例#2
0
        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));
        }