Advertisement
Guest User

Untitled

a guest
May 30th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Threading;
  4.  
  5. namespace __temp_WPF
  6. {
  7. /// <summary>
  8. /// Interaction logic for MainWindow.xaml
  9. /// </summary>
  10. public partial class MainWindow : Window
  11. {
  12. public MainWindow()
  13. {
  14. InitializeComponent();
  15.  
  16. /**
  17. *
  18. * In WPF, Metro, and Windows Form apps, you can subscribe to "global" exception handling events , "respectively":
  19. *
  20. * (1) Application.DispatcherUnhandledException
  21. * (2) Application.ThreadException
  22. *
  23. * These two are only for the UI-thread, main Thread.
  24. *
  25. */
  26.  
  27. Application.Current.DispatcherUnhandledException +=
  28. (object sender, DispatcherUnhandledExceptionEventArgs e) =>
  29. {
  30. MessageBox.Show("A crash occurred, Sorry for the inconvenient. Closing The App.");
  31. e.Handled = true;
  32. App.Current.Shutdown();
  33. };
  34.  
  35. /**
  36. * AppDomai.CurrentThread.UnhandledException fires for any exception on any thread.
  37. * But it fires as the last solution.
  38. * Others may interfene before it
  39. * But since CLR 2.0 , the app will shut down after the handling code is finish.
  40. * To change this behavior,
  41. * add the following to app config file:
  42. *
  43. * <configuration>
  44. * <runtime>
  45. * <legacyUnhandledExceptionPolicy enabled="1" />
  46. * </runtime>
  47. * </configuration>
  48. *
  49. */
  50. }
  51.  
  52. private void Button_Click(object sender, RoutedEventArgs e)
  53. {
  54. throw new Exception("thread exception.");
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement