CSharp-Single-EFCore/Bunny.Service/BackgroundModule/TemplateBackgroundModule.cs

21 lines
683 B
C#

using Microsoft.Extensions.Hosting;
namespace Bunny.Service.BackgroundModule;
/// <summary>
/// 定时任务
/// </summary>
public class TemplateBackgroundModule : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
Console.WriteLine("TemplateService started");
await Task.Delay(1000, stoppingToken);
await Task.Run(() => { Console.WriteLine("执行了。。。"); }, stoppingToken);
await Task.Delay(1000, stoppingToken);
Console.WriteLine("--------------------------------");
}
}
}