change program to async/await

This commit is contained in:
Florian Stinglmayr 2025-08-01 14:23:11 +02:00
parent 387480b2cf
commit 1b7fb26bc4
5 changed files with 40 additions and 8 deletions

@ -1 +1 @@
Subproject commit f21bf5ea5e3116fb1ec44bb90d2917506862d66e Subproject commit ed68876300b2b32b97c2dfc436f3fb98e7f1a45d

View File

@ -25,7 +25,7 @@ internal class Colony : ITreeNode {
} }
public override string ToString() { public override string ToString() {
return $" {System.Name}"; return $" {System.Name}";
} }
} }

View File

@ -28,6 +28,6 @@ internal class Depot : ITreeNode {
public override string ToString() { public override string ToString() {
string percent = (Progress * 100.0).ToString("00.0"); string percent = (Progress * 100.0).ToString("00.0");
return String.Format($" {percent}% {Station.Name}"); return String.Format($" {percent}% {Station.Name}");
} }
} }

View File

@ -22,6 +22,8 @@ internal class Edith {
private static Edith instance = new(); private static Edith instance = new();
public static Edith Instance => instance; public static Edith Instance => instance;
private bool quit = false;
private Edith() { private Edith() {
} }
@ -39,7 +41,32 @@ internal class Edith {
} }
} }
public void Run() { private async Task ProcessQueue() {
while (watcher != null) {
watcher.ProcessQueues();
await Task.Delay(100);
}
}
private async Task RunGUILoop() {
RunState state;
bool first = true;
if (window == null) {
return;
}
state = Application.Begin(window);
while (!quit) {
Application.RunLoop(state);
await Task.Delay(100);
}
Application.End(state);
}
public async Task Run() {
try { try {
SetupJournal(); SetupJournal();
} catch (Exception e) { } catch (Exception e) {
@ -47,10 +74,15 @@ internal class Edith {
return; return;
} }
Application.Init();
window = new MainWindow(); window = new MainWindow();
Application.Init(); Task gui = Task.Run(RunGUILoop);
Application.Run(window); Task queue = Task.Run(ProcessQueue);
await Task.WhenAll([gui, queue]);
window.Dispose(); window.Dispose();
} }
} }

View File

@ -2,7 +2,7 @@
public class Program public class Program
{ {
public static void Main(string[] args) { public static async Task Main(string[] args) {
Edith.Instance.Run(); await Edith.Instance.Run();
} }
} }