1212121
This commit is contained in:
25
Service/Application.Web/Common/AppBackgroundService.cs
Normal file
25
Service/Application.Web/Common/AppBackgroundService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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("启动后台任务执行异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user