Пример #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var config = new NLog.Config.LoggingConfiguration();

            // Targets where to log to: File and Console
            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Changliao", "err.log")
            };

            // Rules for mapping loggers to targets
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            // Apply config
            NLog.LogManager.Configuration = config;
            new Thread(new ThreadStart(() =>
            {
                _ = EmotionManager.shard;
            })).Start();
            new Thread(new ThreadStart(() =>
            {
                BaseSendModel m = new BaseSendModel();
                m.type          = 4;
                HttpUitls.Instance.get <GetVersionReciveModel>("common/getVersion", m, (json) =>
                {
                    if (json.code == 200)
                    {
                        if (json.data == null)
                        {
                            return;
                        }
                        double newversion = Convert.ToDouble(json.data.newVersion);
                        double oldversion = Convert.ToDouble(Properties.Settings.Default.version);
                        if (newversion > oldversion)
                        {
                            if (json.data != null)
                            {
                                if (json.data.is_forced == 1)
                                {
                                    LoginForm loginForm = Application.OpenForms["LoginForm"] as LoginForm;
                                    if (loginForm != null)
                                    {
                                        loginForm.BeginInvoke(new EventHandler((s, e) =>
                                        {
                                            loginForm.Close();
                                        }));
                                        Thread t = new Thread(new ThreadStart(() =>
                                        {
                                            UpdateForm frm = new UpdateForm(json.data.apkUrl);
                                            Application.Run(frm);
                                        }));
                                        t.SetApartmentState(ApartmentState.STA);
                                        t.Start();
                                    }
                                    MainFrm main = Application.OpenForms["MainFrm"] as MainFrm;
                                    if (main != null)
                                    {
                                        main.BeginInvoke(new EventHandler((s, e) =>
                                        {
                                            main.Close();
                                        }));
                                        Thread t = new Thread(new ThreadStart(() =>
                                        {
                                            UpdateForm frm = new UpdateForm(json.data.apkUrl);
                                            Application.Run(frm);
                                        }));
                                        t.SetApartmentState(ApartmentState.STA);
                                        t.Start();
                                    }
                                }
                                else
                                {
                                    if (MessageBox.Show("发现新版本,是否升级?", "版本更新", MessageBoxButtons.OKCancel) == DialogResult.OK)
                                    {
                                        LoginForm loginForm = Application.OpenForms["LoginForm"] as LoginForm;
                                        if (loginForm != null)
                                        {
                                            loginForm.BeginInvoke(new EventHandler((s, e) =>
                                            {
                                                loginForm.Close();
                                            }));
                                            Thread t = new Thread(new ThreadStart(() =>
                                            {
                                                UpdateForm frm = new UpdateForm(json.data.apkUrl);
                                                Application.Run(frm);
                                            }));
                                            t.SetApartmentState(ApartmentState.STA);
                                            t.Start();
                                        }
                                        MainFrm main = Application.OpenForms["MainFrm"] as MainFrm;
                                        if (main != null)
                                        {
                                            main.BeginInvoke(new EventHandler((s, e) =>
                                            {
                                                main.Close();
                                            }));
                                            Thread t = new Thread(new ThreadStart(() =>
                                            {
                                                UpdateForm frm = new UpdateForm(json.data.apkUrl);
                                                Application.Run(frm);
                                            }));
                                            t.SetApartmentState(ApartmentState.STA);
                                            t.Start();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }, (code) =>
                {
                });
            })).Start();
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.Run(new LoginForm());
        }