| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Windows;
- using System.Threading;
- using System.Reflection;
- using SHJX.Service.View.View;
- using SHJX.Service.Common.ReadXML;
- using SHJX.Service.Common.ExtendElement;
- using Microsoft.Extensions.Logging;
- using SHJX.Service.Common.Logging;
- using Microsoft.Extensions.Configuration;
- namespace SHJX.Service.View
- {
- /// <summary>
- /// App.xaml 的交互逻辑
- /// </summary>
- public partial class App : Application {
- //private static readonly ILogger logger = LogFactory.BuildLogger(typeof(Rs485Client));
- private static readonly ILogger logger = LogFactory.BuildLogger(typeof(App));
- private ReadConfigUtil config;
- protected override void OnStartup(StartupEventArgs e)
- {
- try
- {
- config = CreateConfig.CreateReadConfigUtil("shjx");
- var rAssembly = Assembly.GetEntryAssembly();
- var rProductAttribute = (AssemblyProductAttribute)rAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0];
- var mt = new Mutex(true, rProductAttribute.Product, out var ret);
- if (ret)
- {
- base.OnStartup(e);
- LoginForm login = new LoginForm(config);
- var result = login.ShowDialog();
- if (result is not null && Convert.ToBoolean(result))
- {
- MainForm main = new MainForm(config);
- main.ShowDialog();
- }
- }
- else
- {
- UMessageBox.Error("有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。\n\n这个程序即将退出。");
- Current.Shutdown();//退出程序
- return;
- }
- mt.ReleaseMutex();
- Environment.Exit(0);
- }
- catch (Exception ex)
- {
- //logger.LogError(ex.ToString());
- logger?.LogError(ex.ToString());
- //logger.LogError(ex.ToString());
- }
- }
- }
- }
|