mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-04-30 18:43:08 +12:00
Handle failing tasks that are not awaited
This commit is contained in:
parent
f755fc8b4a
commit
4b69295fda
|
@ -1,4 +1,5 @@
|
|||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
|
||||
|
@ -33,5 +34,16 @@ namespace VRCMelonAssistant
|
|||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
public static void NoAwait(this Task task)
|
||||
{
|
||||
task.ContinueWith(t =>
|
||||
{
|
||||
if (t.IsFaulted)
|
||||
{
|
||||
Utils.ShowErrorMessageBox("Exception in free-floating task", t.Exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -409,6 +409,12 @@ namespace VRCMelonAssistant
|
|||
caller.BeginInvoke(Message, null, null, null);
|
||||
}
|
||||
|
||||
public static void ShowErrorMessageBox(string title, Exception ex)
|
||||
{
|
||||
MessageBox.Show(MainWindow.Instance, $"{title}\n{ex}", "Error",
|
||||
MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to write the specified string to the <see cref="System.Windows.Clipboard"/>.
|
||||
/// </summary>
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace VRCMelonAssistant
|
|||
Main.Content = Intro.Instance;
|
||||
break;
|
||||
case "Mods":
|
||||
ShowModsPage();
|
||||
ShowModsPage().NoAwait();
|
||||
break;
|
||||
case "About":
|
||||
Main.Content = About.Instance;
|
||||
|
@ -137,7 +137,7 @@ namespace VRCMelonAssistant
|
|||
|
||||
private void ModsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowModsPage();
|
||||
ShowModsPage().NoAwait();
|
||||
}
|
||||
|
||||
private void IntroButton_Click(object sender, RoutedEventArgs e)
|
||||
|
|
Loading…
Reference in a new issue