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.
60 lines
1.3 KiB
C#
60 lines
1.3 KiB
C#
using System.Diagnostics;
|
|
|
|
using HttpClientStudy.Core.Utils;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
Process currentProcess = Process.GetCurrentProcess();
|
|
currentProcess.EnableRaisingEvents = true;
|
|
currentProcess.Exited += (s, r) =>
|
|
{
|
|
Console.WriteLine("000000000000000000000000000000000000");
|
|
};
|
|
|
|
|
|
// 获取 IHostApplicationLifetime 实例
|
|
var applicationLifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
|
|
|
|
// 注册应用程序关闭事件
|
|
applicationLifetime.ApplicationStopping.Register(() =>
|
|
{
|
|
//关闭WebApi
|
|
StartupUtility.ExitWebApiProject();
|
|
});
|
|
|
|
applicationLifetime.ApplicationStopped.Register(() => {
|
|
Console.WriteLine("xxxxxxxxxxxxxxxxxxxx");
|
|
});
|
|
|
|
// 注册 AppDomain 的未处理异常事件
|
|
AppDomain.CurrentDomain.UnhandledException += (s,e)=>
|
|
{
|
|
Console.WriteLine("退出");
|
|
};
|
|
|
|
|
|
//确保启动WebApi程序
|
|
StartupUtility.StartWebApiProject();
|
|
|
|
app.Run();
|