Exemple #1
0
        private void OnGracefulShutdownRequest(GracefulShutdownRequest request)
        {
            try
            {
                _log.Log(LogCatagory.Info, "ServiceBoot recieved request from {0} to gracefully shutdown service. Reason: {1}", request.Sender, request.Reason);

                _log.Log(LogCatagory.Info, "Stopping Windows service instance...");
                if (Environment.UserInteractive)
                {
                    _serviceInstance.StopInstance();
                }
                else
                {
                    var service = _serviceInstance as ServiceBase;
                    if (service == null)
                    {
                        _log.Log(LogCatagory.Warn, String.Format("Could not cast service instnace to type of ServiceBase. Instance: {0}.", _serviceInstance));
                    }

                    service.Stop();
                }
                _log.Log(LogCatagory.Info, "Completed graceful shutdown of service.");
            }
            catch (Exception e)
            {
                _log.Log(LogCatagory.Error, e, "ServiceBoot caught an unexpected exception while attempting to gracefully shutdown services.");
            }
        }