Program.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. namespace SMBServer
  12. {
  13. static class Program
  14. {
  15. /// <summary>
  16. /// The main entry point for the application.
  17. /// </summary>
  18. [STAThread]
  19. static void Main()
  20. {
  21. Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
  22. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  23. Application.EnableVisualStyles();
  24. Application.SetCompatibleTextRenderingDefault(false);
  25. Application.Run(new ServerUI());
  26. }
  27. public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
  28. {
  29. HandleUnhandledException(e.Exception);
  30. }
  31. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  32. {
  33. if (e.ExceptionObject != null)
  34. {
  35. Exception ex = (Exception)e.ExceptionObject;
  36. HandleUnhandledException(ex);
  37. }
  38. }
  39. private static void HandleUnhandledException(Exception ex)
  40. {
  41. string message = String.Format("Exception: {0}: {1} Source: {2} {3}", ex.GetType(), ex.Message, ex.Source, ex.StackTrace);
  42. MessageBox.Show(message, "Error");
  43. Application.Exit();
  44. }
  45. }
  46. }