alielie
2025-05-12 7bf89fd93bc487e8445d6d85bb527251b7371a04
WPFProject/App.xaml.cs
@@ -2,6 +2,7 @@
using HMI.Core.Util;
using HMI.UI.Util;
using log4net;
using Microsoft.Win32;
using Panuon.WPF.UI;
using System;
using System.IO;
@@ -34,12 +35,34 @@
                    MessageBoxIcon.Error, DefaultButton.YesOK, 5);
        }
        /// <summary>
        /// 启动后往注册表写点东西
        /// </summary>
        private void WriteRegister()
        {
            string Company = "JingCe", Program = "HMI";
            try
            {
                string registryPath = @$"SOFTWARE\{Company}\{Program}";
                using RegistryKey key = Registry.LocalMachine.CreateSubKey(registryPath, true)
                    ?? throw new Exception("无法创建或打开注册表键");
                string path = AppDomain.CurrentDomain.BaseDirectory;
                key.SetValue("Location", path, RegistryValueKind.String);
            }
            catch (Exception ex)
            {
                log.Error("Write Register Failed.", ex);
            }
        }
        private static Mutex mutex;
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            mutex = new Mutex(true, "TestPlatform_OnlyRun_CRNS");
            if (mutex.WaitOne(0, false))
            {
                WriteRegister();
                logCleanner = new LogCleanner();
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                LoggerHelper.Register(new CommonLogger());