Program.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Windows.Forms;
  5. namespace SMBServer
  6. {
  7. static class Program
  8. {
  9. /// <summary>
  10. /// The main entry point for the application.
  11. /// </summary>
  12. [STAThread]
  13. static void Main()
  14. {
  15. Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
  16. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  17. Application.EnableVisualStyles();
  18. Application.SetCompatibleTextRenderingDefault(false);
  19. Application.Run(new ServerUI());
  20. }
  21. public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  22. {
  23. HandleUnhandledException(e.Exception);
  24. }
  25. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  26. {
  27. if (e.ExceptionObject != null)
  28. {
  29. Exception ex = (Exception)e.ExceptionObject;
  30. HandleUnhandledException(ex);
  31. }
  32. }
  33. private static void HandleUnhandledException(Exception ex)
  34. {
  35. string message = String.Format("Exception: {0}: {1} Source: {2} {3}", ex.GetType(), ex.Message, ex.Source, ex.StackTrace);
  36. MessageBox.Show(message, "Error");
  37. Application.Exit();
  38. }
  39. }
  40. }