Skip to content

Commit

Permalink
Added process onexit queue processing to .net standard 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Jun 20, 2016
1 parent 04dded0 commit 7021e45
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static void Startup(this ExceptionlessClient client, string apiKey = null

#if NETSTANDARD1_5 || NET45
client.RegisterAppDomainUnhandledExceptionHandler();
#endif
#if NET45

// make sure that queued events are sent when the app exits
client.RegisterOnProcessExitHandler();
#endif
Expand All @@ -48,8 +47,6 @@ public static void Startup(this ExceptionlessClient client, string apiKey = null
public static void Shutdown(this ExceptionlessClient client) {
#if NETSTANDARD1_5 || NET45
client.UnregisterAppDomainUnhandledExceptionHandler();
#endif
#if NET45
client.UnregisterOnProcessExitHandler();
#endif
client.UnregisterTaskSchedulerUnobservedTaskExceptionHandler();
Expand Down Expand Up @@ -318,9 +315,7 @@ public static void UnregisterAppDomainUnhandledExceptionHandler(this Exceptionle
AppDomain.CurrentDomain.UnhandledException -= _onAppDomainUnhandledException;
_onAppDomainUnhandledException = null;
}
#endif

#if NET45
private static EventHandler _onProcessExit;
public static void RegisterOnProcessExitHandler(this ExceptionlessClient client) {
if (_onProcessExit == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptionless/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"dependencies": {
"Microsoft.CSharp": "4.0.1-rc2-24027",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-final",
"System.AppDomain": "2.0.8",
"System.AppDomain": "2.0.9",
"System.Collections": "4.0.11-rc2-24027",
"System.Collections.Concurrent": "4.0.12-rc2-24027",
"System.ComponentModel.TypeConverter": "4.0.1-rc2-24027",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace Exceptionless {
public static class ExceptionlessWindowsExtensions {
private static EventHandler _onProcessExit;

/// <summary>
/// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
/// </summary>
Expand All @@ -23,9 +21,6 @@ public static void Register(this ExceptionlessClient client, bool showDialog = t
client.SubmitSessionStart();

client.RegisterApplicationThreadExceptionHandler();

// make sure that queued events are sent when the app exits
client.RegisterOnProcessExitHandler();

if (!showDialog)
return;
Expand All @@ -41,7 +36,6 @@ public static void Register(this ExceptionlessClient client, bool showDialog = t
public static void Unregister(this ExceptionlessClient client) {
client.Shutdown();
client.UnregisterApplicationThreadExceptionHandler();
client.UnregisterOnProcessExitHandler();

client.SubmittingEvent -= OnSubmittingEvent;

Expand All @@ -59,31 +53,5 @@ private static void OnSubmittingEvent(object sender, EventSubmittingEventArgs e)
var dialog = new CrashReportForm(e.Client, e.Event);
e.Cancel = dialog.ShowDialog() != DialogResult.OK;
}

private static void RegisterOnProcessExitHandler(this ExceptionlessClient client) {
if (_onProcessExit == null) {
_onProcessExit = (sender, args) => {
client.ProcessQueue();

if (client.Configuration.SessionsEnabled)
client.SubmitSessionEnd();
};
}

try {
AppDomain.CurrentDomain.ProcessExit -= _onProcessExit;
AppDomain.CurrentDomain.ProcessExit += _onProcessExit;
} catch (Exception ex) {
client.Configuration.Resolver.GetLog().Error(typeof(ExceptionlessWindowsExtensions), ex, "An error occurred while wiring up to the process exit event.");
}
}

private static void UnregisterOnProcessExitHandler(this ExceptionlessClient client) {
if (_onProcessExit == null)
return;

AppDomain.CurrentDomain.ProcessExit -= _onProcessExit;
_onProcessExit = null;
}
}
}
34 changes: 1 addition & 33 deletions src/Platforms/Exceptionless.Wpf/ExceptionlessWpfExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Exceptionless {
public static class ExceptionlessWpfExtensions {
private static EventHandler _onProcessExit;

/// <summary>
/// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
/// </summary>
Expand All @@ -26,9 +24,6 @@ public static void Register(this ExceptionlessClient client, bool showDialog = t
client.RegisterApplicationThreadExceptionHandler();
client.RegisterApplicationDispatcherUnhandledExceptionHandler();

// make sure that queued events are sent when the app exits
client.RegisterOnProcessExitHandler();

if (!showDialog)
return;

Expand All @@ -44,8 +39,7 @@ public static void Unregister(this ExceptionlessClient client) {
client.Shutdown();
client.UnregisterApplicationThreadExceptionHandler();
client.UnregisterApplicationDispatcherUnhandledExceptionHandler();
client.UnregisterOnProcessExitHandler();


client.SubmittingEvent -= OnSubmittingEvent;

client.ProcessQueue();
Expand All @@ -68,31 +62,5 @@ private static bool ShowDialog(EventSubmittingEventArgs e) {
bool? result = dialog.ShowDialog();
return result.HasValue && result.Value;
}

private static void RegisterOnProcessExitHandler(this ExceptionlessClient client) {
if (_onProcessExit == null) {
_onProcessExit = (sender, args) => {
client.ProcessQueue();

if (client.Configuration.SessionsEnabled)
client.SubmitSessionEnd();
};
}

try {
AppDomain.CurrentDomain.ProcessExit -= _onProcessExit;
AppDomain.CurrentDomain.ProcessExit += _onProcessExit;
} catch (Exception ex) {
client.Configuration.Resolver.GetLog().Error(typeof(ExceptionlessWpfExtensions), ex, "An error occurred while wiring up to the process exit event.");
}
}

private static void UnregisterOnProcessExitHandler(this ExceptionlessClient client) {
if (_onProcessExit == null)
return;

AppDomain.CurrentDomain.ProcessExit -= _onProcessExit;
_onProcessExit = null;
}
}
}

0 comments on commit 7021e45

Please sign in to comment.