From 85a8677a990da339ca9777def81b2f50a2176ea7 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 19 Mar 2020 09:14:48 -0500 Subject: [PATCH] Log exceptions from failed Tasks --- DS4Windows/DS4Control/Util.cs | 12 ++++++++++++ DS4Windows/DS4Forms/MainWindow.xaml.cs | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/DS4Windows/DS4Control/Util.cs b/DS4Windows/DS4Control/Util.cs index 923aa17..bd784fe 100644 --- a/DS4Windows/DS4Control/Util.cs +++ b/DS4Windows/DS4Control/Util.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Security; +using System.Threading.Tasks; using System.Text; namespace DS4Windows @@ -154,5 +155,16 @@ namespace DS4Windows } catch { } } + + public static void LogAssistBackgroundTask(Task task) + { + task.ContinueWith((t) => + { + if (t.IsFaulted) + { + AppLogger.LogToGui(t.Exception.ToString(), true); + } + }); + } } } diff --git a/DS4Windows/DS4Forms/MainWindow.xaml.cs b/DS4Windows/DS4Forms/MainWindow.xaml.cs index 6832a5c..f1d9dc5 100644 --- a/DS4Windows/DS4Forms/MainWindow.xaml.cs +++ b/DS4Windows/DS4Forms/MainWindow.xaml.cs @@ -124,7 +124,7 @@ namespace DS4WinWPF.DS4Forms public void LateChecks(ArgumentParser parser) { - Task.Run(() => + Task tempTask = Task.Run(() => { CheckDrivers(); if (!parser.Stop) @@ -136,7 +136,9 @@ namespace DS4WinWPF.DS4Forms UpdateTheUpdater(); }); - Task.Delay(100).ContinueWith((t) => + Util.LogAssistBackgroundTask(tempTask); + + tempTask = Task.Delay(100).ContinueWith((t) => { int checkwhen = Global.CheckWhen; if (checkwhen > 0 && DateTime.Now >= Global.LastChecked + TimeSpan.FromHours(checkwhen)) @@ -147,6 +149,7 @@ namespace DS4WinWPF.DS4Forms Global.LastChecked = DateTime.Now; } }); + Util.LogAssistBackgroundTask(tempTask); } private void DownloadUpstreamVersionInfo()