diff --git a/TGServerService/Service.cs b/TGServerService/Service.cs index f7dc75c97f..c4ddfc4496 100644 --- a/TGServerService/Service.cs +++ b/TGServerService/Service.cs @@ -324,19 +324,23 @@ namespace TGServerService /// protected override void OnStop() { - try + lock (this) { - foreach (var I in hosts) + try { - var host = I.Value; - var instance = (ServerInstance)host.SingletonInstance; - host.Close(); - instance.Dispose(); + foreach (var I in hosts) + { + var host = I.Value; + var instance = (ServerInstance)host.SingletonInstance; + host.Close(); + instance.Dispose(); + } } - } - catch (Exception e) - { - WriteEntry(e.ToString(), EventID.ServiceShutdownFail, EventLogEntryType.Error, LoggingID); + catch (Exception e) + { + WriteEntry(e.ToString(), EventID.ServiceShutdownFail, EventLogEntryType.Error, LoggingID); + } + serviceHost.Close(); } Properties.Settings.Default.Save(); ActiveService = null;