周期性后台任务-异步版本

注意事项:

  • 基类是 AsyncBackgroundTask
  • 方法的签名是 Task ExecuteAsync()



示例1 - 休眠N秒的定时任务

public class Task1 : AsyncBackgroundTask
{
    public override int? SleepSeconds => 90;

    public override Task ExecuteAsync()
    {
        Console2.Info("Task1,每隔 90 秒执行一次!");
		// do something....

		await xxxxAsync();
    }
}



示例2 - 基于CronValue的定时任务

public class Task2 : AsyncBackgroundTask
{
    public override string CronValue => "0/10 * * * * ? *";

    public override Task ExecuteAsync()
    {
        Console2.Info("Task2,每隔 10 秒执行一次!");
		// do something....

		await xxxxAsync();
    }
}