Skip to content

Commit

Permalink
Additional exception handling on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyCorbett committed Jan 16, 2019
1 parent 4901ac4 commit af40bdd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
40 changes: 34 additions & 6 deletions OnlyM/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
using AutoUpdates;
using CefSharp;
using CefSharp.Wpf;
Expand All @@ -29,14 +30,22 @@ public partial class App : Application

public App()
{
DispatcherHelper.Initialize();
MediaElement.FFmpegDirectory = FMpegFolderName;
RegisterMappings();
try
{
DispatcherHelper.Initialize();
MediaElement.FFmpegDirectory = FMpegFolderName;
RegisterMappings();

// pre-load the CefSharp assemblies otherwise 1st instantiation is too long.
System.Reflection.Assembly.Load("CefSharp.Wpf");
// pre-load the CefSharp assemblies otherwise 1st instantiation is too long.
System.Reflection.Assembly.Load("CefSharp.Wpf");

_successCefSharp = InitCef();
_successCefSharp = InitCef();
}
catch (Exception ex)
{
AddEventLogEntry(ex.Message);
Current.Shutdown();
}
}

public static string FMpegFolderName { get; } = $"{AppDomain.CurrentDomain.BaseDirectory}\\FFmpeg";
Expand All @@ -56,6 +65,8 @@ protected override void OnStartup(StartupEventArgs e)
else
{
ConfigureLogger();

Current.DispatcherUnhandledException += CurrentDispatcherUnhandledException;
}

if (!_successCefSharp)
Expand Down Expand Up @@ -126,5 +137,22 @@ private bool InitCef()

return Cef.Initialize(settings);
}

private void CurrentDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// unhandled exceptions thrown from UI thread
e.Handled = true;
Log.Logger.Fatal(e.Exception, "Unhandled exception");
Current.Shutdown();
}

private void AddEventLogEntry(string msg)
{
using (var eventLog = new EventLog("Application"))
{
eventLog.Source = "Application";
eventLog.WriteEntry(msg, EventLogEntryType.Error);
}
}
}
}
2 changes: 1 addition & 1 deletion SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.4.0.7")]
[assembly: AssemblyVersion("1.4.0.8")]

0 comments on commit af40bdd

Please sign in to comment.