using LB_SmartVisionLoginUI; using System.Text; namespace LB_SmartVision { internal static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { try { string halconDir = Environment.GetEnvironmentVariable("HALCONROOT"); if (string.IsNullOrEmpty(halconDir) || !Directory.Exists(halconDir)) { System.Windows.Forms.MessageBox.Show("»·¾³±äÁ¿È±ÉÙHALCONROOT,ÇëÈ·ÈÏÊÇ·ñ°²×°ÕýÈ·!"); } else { bool ret; System.Threading.Mutex mutex = new System.Threading.Mutex(true, System.Windows.Forms.Application.ProductName, out ret); if (ret) { ////µÇ¼Ñé֤ȨÏÞ MainWindow.InstanceLoginandConfirmation().ShowDialog(); if (!MainWindow.InstanceLoginandConfirmation().isQuit && MainWindow.InstanceLoginandConfirmation().correctUser) { MainWindow.InstanceLoginandConfirmation().closeLoginFrm(); } else { MainWindow.InstanceLoginandConfirmation().closeLoginFrm(); } //// Main ΪÄã³ÌÐòµÄÖ÷´°Ì壬Èç¹ûÊÇ¿ØÖÆÌ¨³ÌÐò²»ÓÃÕâ¾ä Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); System.Windows.Forms.Application.ThreadException += (sender, e) => HandleException(e.Exception); AppDomain.CurrentDomain.UnhandledException += (sender, e) => HandleException(e.ExceptionObject as Exception); //// To customize application configuration such as set high DPI settings or default font, //// see https://aka.ms/applicationconfiguration. System.Windows.Forms.Application.Run(new VisionForm()); mutex.ReleaseMutex(); } else { System.Windows.Forms.MessageBox.Show("ÓÐÒ»¸öºÍ±¾³ÌÐòÏàͬµÄÓ¦ÓóÌÐòÒѾ­ÔÚÔËÐУ¬Ç벻ҪͬʱÔËÐжà¸ö±¾³ÌÐò¡£\r\nÕâ¸ö³ÌÐò¼´½«Í˳ö¡£", System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); // ÌáʾÐÅÏ¢£¬¿ÉÒÔɾ³ý¡£ System.Windows.Forms.Application.Exit();//Í˳ö³ÌÐò } } } catch (Exception ex) { if (null != ex) { string strMsg = "InitControl failed. Error Code: " + ex.Message; System.Windows.Forms.MessageBox.Show(strMsg); } else { return; } } } static void HandleException(Exception ex) { // ¼Ç¼Òì³£ÐÅÏ¢ string logPath = @"\Logs\app_crash.log"; Directory.CreateDirectory(Path.GetDirectoryName(logPath)); File.AppendAllText(logPath, $"{DateTime.Now}: {ex}\n"); // ÏÔʾ´íÎóÐÅÏ¢£¨¿ÉÑ¡£© System.Windows.Forms.MessageBox.Show($"³ÌÐò·¢Éú´íÎó: {ex.Message}", "´íÎó", MessageBoxButtons.OK, MessageBoxIcon.Error); // Í˳ö³ÌÐò Environment.Exit(1); } } }