public void Shutdown(IShutdownArguments args)
        {
            var handles = Hosts.ToArray().Select(host => ShutdownHost(host, args)).ToArray();
            if (handles.Length > 0)
            {
                if (!WaitHandle.WaitAll(handles, TimeSpan.FromSeconds(100)))
                    log.Error("All services failed to stop in the alotted time.");
            }

            handles.DisposeAll();
            log.Debug("Shutdown.");
        }
 public void Stop(IShutdownArguments arguments)
 {
     MonitoringTask.Stop();
     Stop();
 }
        WaitHandle ShutdownHost(IHostController controller, IShutdownArguments args)
        {
            var handle = new ManualResetEvent(false);
            new Thread(() =>
            {
                try
                {
                    using (controller)
                        controller.Stop(args);
                }
                catch (Exception ex)
                {
                    log.Error(string.Format("Failed to shutdown host '{0}'", controller.Name), ex);
                }
                finally
                {
                    try
                    {
                        handle.Set();
                    }
                    catch (Exception ex)
                    {
                        log.Error("Failed to set handle signalling host stopped.", ex);
                    }

                    Hosts.Remove(controller);
                }
            })
            {
                IsBackground = true
            }
            .Start();

            return handle;
        }
Example #4
0
 public void Stop(IShutdownArguments arguments)
 {
     lock (locker)
     {
         try
         {
             if (Status == HostStatus.Running)
             {
                 WriteLog("Stopping service.", log.Debug);
                 Status = HostStatus.Stopping;
                 Bootstrapper.Stop();
             }
         }
         finally
         {
             Status = HostStatus.Stopped;
             WriteLog("Service stopped.");
         }
     }
 }