C3032
3 天以前 ebcc1d53f14112363bbf539bcaf0202aadcdc9d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using LB_SmartVisionLoginUI;
using System.Text;
 
namespace LB_SmartVision
{
    internal static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [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);
        }
    }
}