You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using Lierda.WPFHelper;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
using SlnMesnac.Common;
|
|
using SlnMesnac.Config;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace SlnMesnac.WPF
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
private System.Threading.Mutex mutex;
|
|
private LierdaCracker cracker = new LierdaCracker();
|
|
public static IServiceProvider ServiceProvider;
|
|
private GunHelper gunHelper = GunHelper.Instance;
|
|
// Startup事件
|
|
protected override async void OnStartup(StartupEventArgs e)
|
|
{
|
|
bool ret;
|
|
mutex = new System.Threading.Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out ret);
|
|
if (!ret)
|
|
{
|
|
MessageBox.Show("应用程序已开启,禁止重复运行");
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
cracker.Cracker(100); //设置GC回收间隔
|
|
|
|
base.OnStartup(e);
|
|
var host = CreateHostBuilder(e.Args).Build();//生成宿主。
|
|
|
|
ServiceProvider = host.Services;
|
|
await host.StartAsync();
|
|
|
|
var appConfig = host.Services.GetService<AppConfig>();
|
|
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
|
|
Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}");
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// CreateHostBuilder
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.UseSerilog()
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
|
|
// Exit事件
|
|
protected override void OnExit(ExitEventArgs e)
|
|
{
|
|
base.OnExit(e);
|
|
|
|
Log.Information($"系统退出,当前时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
|
|
// 释放资源
|
|
// ...
|
|
// 关闭指示灯
|
|
gunHelper.SendData("Exit");
|
|
}
|
|
|
|
|
|
}
|
|
}
|