Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows;
- using System.Windows.Threading;
- namespace __temp_WPF
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- /**
- *
- * In WPF, Metro, and Windows Form apps, you can subscribe to "global" exception handling events , "respectively":
- *
- * (1) Application.DispatcherUnhandledException
- * (2) Application.ThreadException
- *
- * These two are only for the UI-thread, main Thread.
- *
- */
- Application.Current.DispatcherUnhandledException +=
- (object sender, DispatcherUnhandledExceptionEventArgs e) =>
- {
- MessageBox.Show("A crash occurred, Sorry for the inconvenient. Closing The App.");
- e.Handled = true;
- App.Current.Shutdown();
- };
- /**
- * AppDomai.CurrentThread.UnhandledException fires for any exception on any thread.
- * But it fires as the last solution.
- * Others may interfene before it
- * But since CLR 2.0 , the app will shut down after the handling code is finish.
- * To change this behavior,
- * add the following to app config file:
- *
- * <configuration>
- * <runtime>
- * <legacyUnhandledExceptionPolicy enabled="1" />
- * </runtime>
- * </configuration>
- *
- */
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- throw new Exception("thread exception.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement