Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Windows;
- namespace YourNameSpace{
- /// <summary>
- /// Interaction logic for App.xaml
- /// </summary>
- public partial class App:Application {
- protected override void OnStartup(StartupEventArgs e)
- {
- this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
- AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
- base.OnStartup(e);
- }
- void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- if (e.ExceptionObject != null && !e.IsTerminating)
- {
- string msg = e.ExceptionObject.ToString();
- MessageBox.Show(msg, "AppDomain Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- try
- {
- Process.GetCurrentProcess().Kill();
- AppDomain.Unload(AppDomain.CurrentDomain);
- }
- catch { }
- }
- void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
- {
- try
- {
- if (e.Exception != null)
- {
- string msg = "";
- if (e.Exception.InnerException != null)
- {
- msg = e.Exception.InnerException.Message;
- msg += Environment.NewLine;
- msg += Environment.NewLine;
- msg += e.Exception.InnerException.ToString();
- }
- else
- {
- msg = e.Exception.Message;
- msg += Environment.NewLine;
- msg += Environment.NewLine;
- msg += e.Exception.ToString();
- }
- MessageBox.Show(msg, "Dispatcher Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- }
- finally
- {
- e.Handled = true;
- try
- {
- Process.GetCurrentProcess().Kill();
- }
- catch { }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment