Rewrite Initializer.Run so it doesn't look like a toddler made it

This commit is contained in:
John Gross
2019-11-10 15:59:30 -08:00
parent 28164b491b
commit 5727e3b1b8

View File

@@ -125,21 +125,14 @@ quit";
public void Run() public void Run()
{ {
_server = new TorchServer(_config); _server = new TorchServer(_config);
var init = Task.Run(() => _server.Init()).ContinueWith(x =>
if (_config.NoGui)
{ {
if (!x.IsFaulted) _server.Init();
return; _server.Start();
}
Log.Error("Error initializing server."); else
LogException(x.Exception);
});
if (!_config.NoGui)
{ {
if (_config.Autostart)
init.ContinueWith(x => _server.Start());
Log.Info("Showing UI");
#if !DEBUG #if !DEBUG
if (!_config.IndependentConsole) if (!_config.IndependentConsole)
{ {
@@ -147,13 +140,19 @@ quit";
NativeMethods.FreeConsole(); NativeMethods.FreeConsole();
} }
#endif #endif
new TorchUI(_server).ShowDialog(); var gameThread = new Thread(() =>
} {
else _server.Init();
{
init.Wait(); if (_config.Autostart)
_server.Start(); _server.Start();
});
gameThread.Start();
var ui = new TorchUI(_server);
ui.ShowDialog();
} }
} }