Skip to content
forked from sgbj/crontimer

Like PeriodicTimer but for cron jobs. Forked to lower minimum .NET version.

License

Notifications You must be signed in to change notification settings

Kevinf63/crontimer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sgbj.Cron.CronTimer

Provides a cron timer similar to System.Threading.PeriodicTimer that enables waiting asynchronously for timer ticks.

Available on NuGet.

Usage

Normal usage:

// Every minute
using var timer = new CronTimer("* * * * *");

while (await timer.WaitForNextTickAsync())
{
    // Do work
}

Example hosted service:

public class CronJob : BackgroundService
{
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        // Every day at 8am local time
        using var timer = new CronTimer("0 8 * * *", TimeZoneInfo.Local);

        while (await timer.WaitForNextTickAsync(stoppingToken))
        {
            // Do work
        }
    }
}

Non-standard cron expression:

// Every 30 seconds
using var timer = new CronTimer(CronExpression.Parse("*/30 * * * * *", CronFormat.IncludeSeconds));

Resources

About

Like PeriodicTimer but for cron jobs. Forked to lower minimum .NET version.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%