Services: Add Utils.RunForeground() to factor Task.Run and try-catch-Blocks out
Test / Run tests (push) Successful in 2m2s

This commit is contained in:
2026-06-30 02:27:57 +02:00
parent 69efca1cc3
commit beacba6bd9
6 changed files with 188 additions and 291 deletions
+17 -3
View File
@@ -31,6 +31,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
namespace Elwig.Helpers {
@@ -209,16 +210,29 @@ namespace Elwig.Helpers {
return Regex.Replace(iban.Trim(), ".{4}", "$0 ").Trim();
}
public static void RunBackground(string title, Func<Task> a) {
public static void RunBackground(string title, Func<Task> function) {
Task.Run(async () => {
try {
await a();
await function();
} catch (Exception exc) {
InteractionService.ShowException(title, exc);
}
});
}
public static async Task RunForeground(Func<Task> function) {
var isSTA = Thread.CurrentThread.GetApartmentState() == ApartmentState.STA;
if (isSTA) Mouse.OverrideCursor = Cursors.Wait;
await Task.Run(async () => {
try {
await function();
} catch (Exception exc) {
InteractionService.ShowException(exc);
}
});
if (isSTA) Mouse.OverrideCursor = null;
}
public static void MailTo(string emailAddress) {
MailTo([emailAddress]);
}
@@ -579,7 +593,7 @@ namespace Elwig.Helpers {
await doc.Generate(ctx);
}
doc.SaveTo(filename);
Process.Start("explorer.exe", filename);
if (!App.Config.Debug) Process.Start("explorer.exe", filename);
}
} else {
using (var ctx = new AppDbContext()) {