Thread termination fix
This commit is contained in:
@ -8,7 +8,7 @@ namespace RageCoop.Server
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static bool ReadyToStop = false;
|
||||
private static bool Stopping = false;
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var mainLogger= new Core.Logger()
|
||||
@ -18,45 +18,45 @@ namespace RageCoop.Server
|
||||
};
|
||||
try
|
||||
{
|
||||
#if DEBUG
|
||||
new Thread(async () =>
|
||||
{
|
||||
do
|
||||
{
|
||||
Console.Title = string.Format("RAGECOOP [{0,5:P2}] [{1:F}MB]", await GetCpuUsageForProcess(), Process.GetCurrentProcess().PrivateMemorySize64 * 0.000001);
|
||||
|
||||
Thread.Sleep(500);
|
||||
} while (true);
|
||||
}).Start();
|
||||
#else
|
||||
Console.Title = "RAGECOOP";
|
||||
var setting = Util.Read<ServerSettings>("Settings.xml");
|
||||
#if DEBUG
|
||||
setting.LogLevel=0;
|
||||
#endif
|
||||
|
||||
var server = new Server(setting, mainLogger);
|
||||
Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
|
||||
{
|
||||
mainLogger.Info("Initiating shutdown sequence...");
|
||||
mainLogger.Info("Press Ctrl+C again to commence an emergency shutdown.");
|
||||
if (e.SpecialKey == ConsoleSpecialKey.ControlC)
|
||||
{
|
||||
if (!ReadyToStop)
|
||||
if (!Stopping)
|
||||
{
|
||||
e.Cancel = true;
|
||||
ReadyToStop = true;
|
||||
Stopping = true;
|
||||
server.Stop();
|
||||
mainLogger.Info("Server stopped.");
|
||||
mainLogger.Dispose();
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
else
|
||||
{
|
||||
mainLogger.Flush();
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_ = new Server(Util.Read<ServerSettings>("Settings.xml"), mainLogger);
|
||||
server.Start();
|
||||
mainLogger?.Info("Please use CTRL + C if you want to stop the server!");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
mainLogger.Error(e);
|
||||
mainLogger.Error($"Fatal error occurred, server shutting down.");
|
||||
Thread.Sleep(3000);
|
||||
mainLogger.Flush();
|
||||
Thread.Sleep(5000);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
mainLogger.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user