change program to async/await
This commit is contained in:
Submodule EDPlayerJournal updated: f21bf5ea5e...ed68876300
@@ -25,7 +25,7 @@ internal class Colony : ITreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return $" ☀ {System.Name}";
|
return $" {System.Name}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/Edith.cs
38
src/Edith.cs
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user