Пример #1
0
        public void Run()
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            _osCommands.CheckToSeeIfServiceRunning(_description);

            try
            {
                _log.Debug("Starting up as a console application");

                _exit = new ManualResetEvent(false);

                Console.CancelKeyPress += HandleCancelKeyPress;

                _coordinator.Start();                 //user code starts

                _log.InfoFormat("[Topshelf] Running, press Control+C to exit.");

                _exit.WaitOne();
            }
            catch (Exception ex)
            {
                _log.Error("An exception occurred", ex);
            }
            finally
            {
                ShutdownCoordinator();
                _exit.Close();
            }
        }
Пример #2
0
        protected override void OnStart(string[] args)
        {
            try
            {
                _log.Info("[Topshelf] Starting");

                _log.DebugFormat("[Topshelf] Arguments: {0}", string.Join(",", args));

                _coordinator.Start();
            }
            catch (Exception ex)
            {
                _log.Fatal(ex);
                throw;
            }
        }
Пример #3
0
        public void Start()
        {
            CheckToSeeIfWinServiceRunning();
            "Daemon loading in console...".ToDebug <IDaemon>();
            var externalTriggeredTerminatation = new ManualResetEvent(false);
            var waitHandles = new WaitHandle[] { externalTriggeredTerminatation };

            Console.CancelKeyPress += delegate
            {
                "Exiting.".ToInfo <IDaemon>();
                ServiceCoordinator.Stop();
                ServiceCoordinator.Dispose();
                externalTriggeredTerminatation.Set();
            };

            ServiceCoordinator.Start();
            "Daemon started, press Control+C to exit."
            .ToInfo <IDaemon>();
            WaitHandle.WaitAny(waitHandles);
        }
Пример #4
0
        public void Run()
        {
            _log.Debug("Starting up as a console application");
            var internalallyTriggeredTermination = new ManualResetEvent(false);
            var externalTriggeredTerminatation   = new ManualResetEvent(false);
            var waitHandles = new WaitHandle[] { internalallyTriggeredTermination, externalTriggeredTerminatation };

            _coordinator.Stopped   += (() => internalallyTriggeredTermination.Set());
            Console.CancelKeyPress += delegate
            {
                _log.Info("Control+C detected, exiting.");
                _log.Info("Stopping the service");
                _coordinator.Stop(); //user stop
                _coordinator.Dispose();
                externalTriggeredTerminatation.Set();
            };
            _coordinator.Start(); //user code starts
            _log.InfoFormat("The service is running, press Control+C to exit.");
            WaitHandle.WaitAny(waitHandles);
            //will wait until a termination trigger occurs
        }
Пример #5
0
 protected override void OnStart(string[] args)
 {
     ServiceCoordinator.Start();
 }