Files
BabyVideoService/Program.cs
2026-02-08 16:58:32 +08:00

60 lines
1.4 KiB
C#

using System.Diagnostics;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.DependencyInjection;
using ACBuildService;
public class Program
{
private static volatile Task _loopTask;
private static volatile Task _shutDownTask;
public static async Task Main(string[] args)
{
App.Init();
Test();
await HttpService.Start();
ExitHandle();
_loopTask = EnterAsync();
await _loopTask;
}
private static async Task EnterAsync()
{
while (App.Running)
{
await Task.Delay(10);
App.Update();
App.LateUpdate();
}
Log.Info("Stop");
}
private static void ExitHandle()
{
//退出监听
AppDomain.CurrentDomain.ProcessExit += (_, _) => { ServerExitConfirm(); };
//Fetal异常监听
AppDomain.CurrentDomain.UnhandledException += (_, e) => { ServerExitConfirm(); };
//ctrl+c
Console.CancelKeyPress += (_, _) => { ServerExitConfirm(); };
}
private static void ServerExitConfirm()
{
Log.Info("开始执行退出程序");
_shutDownTask = Task.Run(() =>
{
App.Running = false;
_loopTask?.Wait();
Console.WriteLine("退出完成");
Process.GetCurrentProcess().Kill();
});
_shutDownTask.Wait();
}
private static void Test()
{
}
}