move ui lifetime to a manager for better lifetime control
All checks were successful
Release / Get Version (push) Successful in 4s
Release / Build and Publish Nuget (push) Successful in 2m21s
Release / Build and Publish Package (push) Successful in 2m58s

This commit is contained in:
zznty
2024-10-23 16:52:10 +07:00
parent 264daf7515
commit d301955609
5 changed files with 50 additions and 21 deletions

View File

@@ -93,27 +93,11 @@ namespace Torch.Server
#endif
_server.Init();
var uiThread = new Thread(() =>
{
var ui = new TorchUI(_server);
SynchronizationContext.SetSynchronizationContext(
new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
ui.ShowDialog();
});
uiThread.SetApartmentState(ApartmentState.STA);
uiThread.Start();
if (Config.Autostart || Config.TempAutostart)
{
Config.TempAutostart = false;
_server.Start();
}
uiThread.Join();
if (!Config.Autostart && !Config.TempAutostart) return;
Config.TempAutostart = false;
_server.Start();
}
}