forced stop & restart in separate thread
This commit is contained in:
@@ -178,6 +178,17 @@ namespace Torch.Server
|
||||
{
|
||||
if (State == ServerState.Stopped)
|
||||
Log.Error("Server is already stopped");
|
||||
if (Thread.CurrentThread == GameThread)
|
||||
new Thread(StopInternal)
|
||||
{
|
||||
Name = "Stopping Thread"
|
||||
}.Start();
|
||||
else
|
||||
StopInternal();
|
||||
}
|
||||
|
||||
private void StopInternal()
|
||||
{
|
||||
Log.Info("Stopping server.");
|
||||
base.Stop();
|
||||
Log.Info("Server stopped.");
|
||||
@@ -202,8 +213,9 @@ namespace Torch.Server
|
||||
Log.Info("Ejected all players from server for restart.");
|
||||
}
|
||||
|
||||
Stop();
|
||||
// TODO clone this
|
||||
new Thread(() =>
|
||||
{
|
||||
StopInternal();
|
||||
var config = (TorchConfig)Config;
|
||||
LogManager.Flush();
|
||||
|
||||
@@ -213,6 +225,10 @@ namespace Torch.Server
|
||||
Process.Start(exe, config.ToString());
|
||||
|
||||
Environment.Exit(0);
|
||||
})
|
||||
{
|
||||
Name = "Restart thread"
|
||||
}.Start();
|
||||
}
|
||||
|
||||
[SuppressPropertyChangedWarnings]
|
||||
|
@@ -472,7 +472,8 @@ namespace Torch
|
||||
{
|
||||
// Kinda icky, but we can't block the update and expect the state to change.
|
||||
if (Thread.CurrentThread == _updateThread)
|
||||
return _state == state;
|
||||
throw new InvalidOperationException(
|
||||
"Waiting for game state is not possible from update thread (deadlock)");
|
||||
|
||||
DateTime? end = timeout.HasValue ? (DateTime?) (DateTime.Now + timeout.Value) : null;
|
||||
while (_state != state && (!end.HasValue || end > DateTime.Now + TimeSpan.FromSeconds(1)))
|
||||
|
Reference in New Issue
Block a user