Added more proper logging of background thread exceptions

This commit is contained in:
Travis Nickles 2020-03-23 22:10:47 -05:00
parent 4ec4eb830f
commit 529adf9f27
2 changed files with 33 additions and 4 deletions

View File

@ -128,6 +128,7 @@ namespace DS4WinWPF
logHolder = new LoggerHolder(rootHub);
DispatcherUnhandledException += App_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Logger logger = logHolder.Logger;
string version = DS4Windows.Global.exeversion;
logger.Info($"DS4Windows version {version}");
@ -173,6 +174,26 @@ namespace DS4WinWPF
window.LateChecks(parser);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (!Current.Dispatcher.CheckAccess())
{
Logger logger = logHolder.Logger;
Exception exp = e.ExceptionObject as Exception;
logger.Error($"Thread App Crashed with message {exp.Message}");
logger.Error(exp.ToString());
//LogManager.Flush();
//LogManager.Shutdown();
if (e.IsTerminating)
{
Dispatcher.Invoke(() =>
{
CleanShutdown(1);
});
}
}
}
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
//Console.WriteLine("App Crashed");
@ -450,7 +471,7 @@ namespace DS4WinWPF
CleanShutdown();
}
private void CleanShutdown()
private void CleanShutdown(int exitCode = 0)
{
if (runShutdown)
{
@ -458,6 +479,7 @@ namespace DS4WinWPF
{
Task.Run(() =>
{
if (rootHub.running)
rootHub.Stop();
}).Wait();
}
@ -481,6 +503,11 @@ namespace DS4WinWPF
LogManager.Flush();
LogManager.Shutdown();
if (exitCode != 0)
{
Current.Shutdown(exitCode);
}
}
}
}

View File

@ -608,7 +608,9 @@ namespace DS4Windows
try
{
exitInputThread = true;
//ds4Input.Abort();
if (ds4Input.ThreadState.HasFlag(System.Threading.ThreadState.WaitSleepJoin))
ds4Input.Interrupt();
else
ds4Input.Join();
}
catch (Exception e)