SirCmpwn

Untitled

Jun 2nd, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
  2. [STAThread]
  3. static void Main(string[] args)
  4. {
  5. Application.EnableVisualStyles();
  6. Application.SetCompatibleTextRenderingDefault(false);
  7. if (!System.Diagnostics.Debugger.IsAttached)
  8. {
  9. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  10. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
  11. Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
  12. }
  13.  
  14. //...
  15.  
  16. static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  17. {
  18. CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, false));
  19. }
  20.  
  21. static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  22. {
  23. UnhandledExceptionForm uef = new UnhandledExceptionForm(e.ExceptionObject as Exception);
  24. uef.ShowDialog();
  25. }
  26.  
  27. // UnhandledExceptionForm will close the application if needed
Advertisement
Add Comment
Please, Sign In to add comment