Log exceptions from failed Tasks

This commit is contained in:
Travis Nickles 2020-03-19 09:14:48 -05:00
parent ee97a49097
commit 85a8677a99
2 changed files with 17 additions and 2 deletions

View File

@ -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);
}
});
}
}
}

View File

@ -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()