diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs
index b0e7a9e..0f0e83e 100644
--- a/Torch.Server/TorchServer.cs
+++ b/Torch.Server/TorchServer.cs
@@ -69,6 +69,14 @@ namespace Torch.Server
_simUpdateTimer.Elapsed += SimUpdateElapsed;
_simUpdateTimer.Start();
+
+ Console.CancelKeyPress += (_, _) =>
+ {
+ if (State == ServerState.Running)
+ Stop();
+
+ Environment.Exit(0);
+ };
}
private void SimUpdateElapsed(object sender, System.Timers.ElapsedEventArgs e)
@@ -239,9 +247,14 @@ namespace Torch.Server
StopInternal();
LogManager.Flush();
+ if (
#if DEBUG
- Environment.Exit(0);
+ // ReSharper disable once ConditionIsAlwaysTrueOrFalse
+ true ||
#endif
+ ApplicationContext.Current.IsService
+ )
+ Environment.Exit(0);
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");
diff --git a/Torch.Server/Views/TorchUI.xaml.cs b/Torch.Server/Views/TorchUI.xaml.cs
index 7bbefd8..aa8542a 100644
--- a/Torch.Server/Views/TorchUI.xaml.cs
+++ b/Torch.Server/Views/TorchUI.xaml.cs
@@ -116,7 +116,7 @@ namespace Torch.Server
if (_server?.State == ServerState.Running)
_server.Stop();
- Process.GetCurrentProcess().Kill();
+ Environment.Exit(0);
}
}
}
diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs
index 932d70c..400c3c7 100644
--- a/Torch/TorchBase.cs
+++ b/Torch/TorchBase.cs
@@ -372,10 +372,10 @@ namespace Torch
///
public virtual void Stop()
{
- LogManager.Flush();
Game.SignalStop();
- if (!Game.WaitFor(VRageGame.GameState.Stopped))
+ if (!Game.WaitFor(VRageGame.GameState.Stopped, TimeSpan.FromSeconds(Config.TickTimeout)))
Log.Warn("Failed to wait for the game to be stopped");
+ LogManager.Flush();
}
///