🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

Sgbj.Cron.CronTimer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Sgbj.Cron.CronTimer

Like PeriodicTimer but for cron jobs.

1.0.2
Source
NuGet
Version published
Maintainers
1
Created
Source

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

  • Hangfire/Cronos - Library for working with cron expressions.
  • Crontab.guru - The cron schedule expression editor.

Keywords

cron

FAQs

Package last updated on 25 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts