forced stop & restart in separate thread
This commit is contained in:
@@ -178,6 +178,17 @@ namespace Torch.Server
|
|||||||
{
|
{
|
||||||
if (State == ServerState.Stopped)
|
if (State == ServerState.Stopped)
|
||||||
Log.Error("Server is already 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.");
|
Log.Info("Stopping server.");
|
||||||
base.Stop();
|
base.Stop();
|
||||||
Log.Info("Server stopped.");
|
Log.Info("Server stopped.");
|
||||||
@@ -202,17 +213,22 @@ namespace Torch.Server
|
|||||||
Log.Info("Ejected all players from server for restart.");
|
Log.Info("Ejected all players from server for restart.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Stop();
|
new Thread(() =>
|
||||||
// TODO clone this
|
{
|
||||||
var config = (TorchConfig)Config;
|
StopInternal();
|
||||||
LogManager.Flush();
|
var config = (TorchConfig)Config;
|
||||||
|
LogManager.Flush();
|
||||||
|
|
||||||
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
|
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
|
||||||
config.WaitForPID = Environment.ProcessId.ToString();
|
config.WaitForPID = Environment.ProcessId.ToString();
|
||||||
config.TempAutostart = true;
|
config.TempAutostart = true;
|
||||||
Process.Start(exe, config.ToString());
|
Process.Start(exe, config.ToString());
|
||||||
|
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
})
|
||||||
|
{
|
||||||
|
Name = "Restart thread"
|
||||||
|
}.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressPropertyChangedWarnings]
|
[SuppressPropertyChangedWarnings]
|
||||||
|
@@ -472,7 +472,8 @@ namespace Torch
|
|||||||
{
|
{
|
||||||
// Kinda icky, but we can't block the update and expect the state to change.
|
// Kinda icky, but we can't block the update and expect the state to change.
|
||||||
if (Thread.CurrentThread == _updateThread)
|
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;
|
DateTime? end = timeout.HasValue ? (DateTime?) (DateTime.Now + timeout.Value) : null;
|
||||||
while (_state != state && (!end.HasValue || end > DateTime.Now + TimeSpan.FromSeconds(1)))
|
while (_state != state && (!end.HasValue || end > DateTime.Now + TimeSpan.FromSeconds(1)))
|
||||||
|
Reference in New Issue
Block a user