Services: Add Utils.RunForeground() to factor Task.Run and try-catch-Blocks out
Test / Run tests (push) Successful in 2m2s
Test / Run tests (push) Successful in 2m2s
This commit is contained in:
+17
-3
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user