Files
Kg.SeaTime/Service/Application.Web/Common/AppBackgroundService.cs
2026-07-07 18:43:01 +08:00

25 lines
864 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Application.Web;
public class AppBackgroundService:BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
Console.WriteLine("应用启动完成,开始执行初始化后台任务");
// ========== 你要执行的启动方法写在这里 ==========
var jobService = App.GetService<IGameAutoJobService>();
await jobService.StartJob();
// ==========================================
Console.WriteLine("启动初始化任务执行完成");
// 如果只需要执行一次直接退出如果是常驻定时任务就写while循环
return;
}
catch (Exception ex)
{
Console.WriteLine("启动后台任务执行异常");
}
}
}