alielie
2025-03-17 c401a2f2fd1a509cdeb33e850bb5c2827074af48
WPFProject/App.xaml.cs
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using HMI.Core.Setting;
using HMI.Core.Util;
using HMI.UI.Util;
using log4net;
using Panuon.WPF.UI;
using System;
using System.Threading;
using System.Windows;
using WPFProject.Utils;
namespace WPFProject
{
@@ -13,15 +15,45 @@
    /// </summary>
    public partial class App : Application
    {
        public void test()
        private ILog log;
        public App()
        {
            log = LogManager.GetLogger("APP");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var ex = e.ExceptionObject as Exception;
            log.Error("UnhandledException.", ex);
            MsgBoxHelper.ErrorMessage(Current.MainWindow, this.lang("App.AppUnhandledException",ex.Message),
                    this.lang("App.Error"), MessageBoxButton.OK,
                    MessageBoxIcon.Error, DefaultButton.YesOK, 5);
        }
        private static Mutex mutex;
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            MainWindow window = new MainWindow();
            window.Show();
            mutex = new System.Threading.Mutex(true, "TestPlatform_OnlyRun_CRNS");
            if (mutex.WaitOne(0, false))
            {
                LangUtil.Load();
                SystemSetting.SystemSettingChanged += SystemSetting_SystemSettingChanged;
                ToastHelper.Register(new MainToastHandler());
                //LoadingWindow window = new LoadingWindow();
                Login window = new Login();
                window.Show();
            }
            else
            {
                MessageBox.Show("程序已经在运行!", "提示");
                this.Shutdown();
            }
        }
        private void SystemSetting_SystemSettingChanged(object sender, SystemSetting e)
        {
            LangUtil.LoadLang();
        }
    }
}