Exemplo n.º 1
0
 /// <summary>Called when [key pressed].</summary>
 /// <param name="keyInfo">The key information.</param>
 protected internal virtual void OnKeyPressed(ConsoleKeyInfo keyInfo)
 {
     if (keyInfo.Key == ConsoleKey.Escape)
     {
         var now  = DateTime.Now;
         var time = now - onKeyPressedEscape;
         onKeyPressedEscape = now;
         if (time > TimeSpan.Zero && time < OnKeyPressedEscapeShutdownTimeSpan)
         {
             ServiceParameters.CommitShutdown();
         }
         else
         {
             log.LogInfo("Press escape within <cyan>{0}<default> to perform shutdown.", OnKeyPressedEscapeShutdownTimeSpan.FormatTime());
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>Tells the worker to shutdown by setting the <see cref="ServiceParameters"/>.</summary>
        protected override void OnStop()
        {
            if (ServiceParameters == null)
            {
                return;
            }

            log.LogInfo("Stopping service <cyan>{0}<default>...", ServiceName);
            ServiceParameters.IsStopping = true;
            if (!ServiceParameters.CommandLineMode)
            {
                base.OnStop();
            }

            ServiceParameters.CommitShutdown();
            if (task != null)
            {
                task.Wait();
                task = null;
            }
            ServiceParameters = null;
            log.LogInfo("Service <cyan>{0}<default> stopped.", ServiceName);
        }