diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index 8f59f3d4..4c54a161 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -220,6 +220,7 @@ void DoRestart(Task task, object torch0) { config.TempAutostart = true; torch.Stop(); + torch.Destroy(); } LogManager.Flush(); diff --git a/Torch.Server/TorchService.cs b/Torch.Server/TorchService.cs index 1a659b8d..fdc5c70e 100644 --- a/Torch.Server/TorchService.cs +++ b/Torch.Server/TorchService.cs @@ -45,7 +45,11 @@ protected override void OnStart(string[] _) protected override void OnStop() { var mre = new ManualResetEvent(false); - Task.Run(() => _initializer.Server.Stop()); + Task.Run(() => + { + _initializer.Server.Stop(); + _initializer.Server.Destroy(); + }); if (!mre.WaitOne(TimeSpan.FromMinutes(1))) Process.GetCurrentProcess().Kill(); } diff --git a/Torch.Server/Views/TorchUI.xaml.cs b/Torch.Server/Views/TorchUI.xaml.cs index 6e8f4048..fed564bc 100644 --- a/Torch.Server/Views/TorchUI.xaml.cs +++ b/Torch.Server/Views/TorchUI.xaml.cs @@ -164,8 +164,16 @@ private void BtnStop_Click(object sender, RoutedEventArgs e) { var result = MessageBox.Show("Are you sure you want to stop the server?", "Stop Server", MessageBoxButton.YesNo); - if (result == MessageBoxResult.Yes) - _server.Invoke(() => _server.Stop()); + if (result != MessageBoxResult.Yes) + { + return; + } + + Task.Run(() => + { + _server.Stop(); + _server.Destroy(); + }); } protected override void OnClosing(CancelEventArgs e) @@ -180,7 +188,10 @@ protected override void OnClosing(CancelEventArgs e) //_config.Save(); //you idiot if (_server?.State == ServerState.Running) + { _server.Stop(); + _server.Destroy(); + } _scrollTimer.Stop(); diff --git a/Torch/Commands/TorchCommands.cs b/Torch/Commands/TorchCommands.cs index c1f660d9..fb6ff253 100644 --- a/Torch/Commands/TorchCommands.cs +++ b/Torch/Commands/TorchCommands.cs @@ -341,12 +341,14 @@ private IEnumerable StopCountdown(int countdown, bool save) ITorchBase torch = (mod as CommandModule)?.Context?.Torch; Debug.Assert(torch != null); torch.Stop(); + torch.Destroy(); }, this, TaskContinuationOptions.RunContinuationsAsynchronously); } else { Log.Info("Stopping server."); - Context.Torch.Invoke(() => Context.Torch.Stop()); + Context.Torch.Stop(); + Context.Torch.Destroy(); } @@ -407,7 +409,7 @@ private IEnumerable RestartCountdown(int countdown, bool save) } Log.Warn("Initiating server restart."); - Context.Torch.Invoke(() => Context.Torch.Restart(save)); + Context.Torch.Restart(save); yield break; }