using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
public static void Main()
Console.WriteLine("Hello World");
public class MyTestHostedService : BackgroundService
private CrontabSchedule _schedule;
private DateTime _nextRun;
private string Schedule => "*/10 * * * * *";
public MyTestHostedService()
_schedule = CrontabSchedule.Parse(Schedule,new CrontabSchedule.ParseOptions { IncludingSeconds = true });
_nextRun = _schedule.GetNextOccurrence(DateTime.Now);
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var nextrun = _schedule.GetNextOccurrence(now);
_nextRun = _schedule.GetNextOccurrence(DateTime.Now);
await Task.Delay(5000, stoppingToken);
while (!stoppingToken.IsCancellationRequested);
Console.WriteLine("hello world"+ DateTime.Now.ToString("F"));