| | |
| | | using LB_SmartVisionLoginUI; |
| | | using System.Text; |
| | | |
| | | namespace LB_SmartVision |
| | | { |
| | | internal static class Program |
| | |
| | | [STAThread] |
| | | static void Main() |
| | | { |
| | | // To customize application configuration such as set high DPI settings or default font, |
| | | // see https://aka.ms/applicationconfiguration. |
| | | ApplicationConfiguration.Initialize(); |
| | | Application.Run(new VisionForm()); |
| | | 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(); |
| | | 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()); |
| | | } |
| | | // Main ä¸ºä½ ç¨åºç主çªä½ï¼å¦ææ¯æ§å¶å°ç¨åºä¸ç¨è¿å¥ |
| | | 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); |
| | | } |
| | | } |
| | | } |