namespace HisenceYoloDetection { internal static class Program { static MainForm? mainFrm = null; static Form1? form1 = null; /// /// The main entry point for the application. /// [STAThread] static void Main() { try { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); mainFrm = new MainForm(); Application.Run(mainFrm); //form1 = new Form1(); //Application.Run(form1); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += Application_ThreadException; }catch (Exception ex) { } } private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { string msg = e.Exception.Message; using (StreamWriter sw = new StreamWriter("D://ThreadException.log", true)) { sw.WriteLine("================================"); sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); sw.WriteLine(msg); sw.Flush(); } if (mainFrm != null) { // mainFrm.DockFrm_OnLogMsgOutput(new LogMsg(DateTime.Now, EnumHelper.LogLevel.Exception, msg)); } //MessageBox.Show(msg, "线程异常报警"); } private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { string msg = (e.ExceptionObject as Exception).Message; using (StreamWriter sw = new StreamWriter("D://UnhandledException.log", true)) { sw.WriteLine("================================"); sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); sw.WriteLine(msg); sw.Flush(); } if (mainFrm != null) { //mainFrm.DockFrm_OnLogMsgOutput(new LogMsg(DateTime.Now, EnumHelper.LogLevel.Exception, msg)); //MessageBox.Show(msg, "未处理异常"); } } } }