private void ExitThread(object state) { Logger.LogVerbose("Завершение работы приложения..."); var sortedList = new SortedList <int, List <ISubsystem> >(_subsystems.Count); foreach (var pair in _subsystems) { var subsystem = pair.Value; if (sortedList.ContainsKey(subsystem.DisposeOrder)) { sortedList[subsystem.DisposeOrder].Add(subsystem); } else { sortedList.Add(subsystem.DisposeOrder, new List <ISubsystem> { subsystem }); } } foreach (var pair in sortedList) { foreach (var subsystem in pair.Value) { Logger.LogVerbose(string.Format("Останов подсистемы '{0}'...", subsystem.Name)); Disposer.DisposeObject(subsystem); } } Thread.Sleep(1000); foreach (var pair in sortedList) { foreach (var subsystem in pair.Value) { Logger.LogVerbose(string.Format("Останов журналирования подсистемы '{0}'...", subsystem.Name)); subsystem.DisposeLogger(); } } var exitType = state == null ? "не задан" : ((ApplicationExitType)state).ToString(); Logger.LogInfo("Завершение работы приложения (тип выхода {0})", exitType); Thread.Sleep(1000); Disposer.DisposeObject(Logger); FileWriter.Close(); _exitEvent.Set(); Thread.Sleep(1000); if (state == null) { return; } Exited.RaiseEvent(this, new ApplicationExitEventArgs((ApplicationExitType)state)); var exitCode = (int)state; LoggingUtils.LogToConsole("exit with code: {0}", exitCode); Environment.Exit(exitCode); }