Provides a cron timer similar to System.Threading.PeriodicTimer that enables waiting asynchronously for timer ticks.
Available on NuGet.
Normal usage:
// Every minuteusingvartimer=newCronTimer("* * * * *");while(awaittimer.WaitForNextTickAsync()){// Do work}Example hosted service:
publicclassCronJob:BackgroundService{protectedoverrideasyncTaskExecuteAsync(CancellationTokenstoppingToken){// Every day at 8am local timeusingvartimer=newCronTimer("0 8 * * *",TimeZoneInfo.Local);while(awaittimer.WaitForNextTickAsync(stoppingToken)){// Do work}}}Non-standard cron expression:
// Every 30 secondsusingvartimer=newCronTimer(CronExpression.Parse("*/30 * * * * *",CronFormat.IncludeSeconds));- Hangfire/Cronos - Library for working with cron expressions.
- Crontab.guru - The cron schedule expression editor.