LaquaiLib.Threading.CronTimer 0.1.0

dotnet add package LaquaiLib.Threading.CronTimer --version 0.1.0
                    
NuGet\Install-Package LaquaiLib.Threading.CronTimer -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LaquaiLib.Threading.CronTimer" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LaquaiLib.Threading.CronTimer" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="LaquaiLib.Threading.CronTimer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LaquaiLib.Threading.CronTimer --version 0.1.0
                    
#r "nuget: LaquaiLib.Threading.CronTimer, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LaquaiLib.Threading.CronTimer@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LaquaiLib.Threading.CronTimer&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=LaquaiLib.Threading.CronTimer&version=0.1.0
                    
Install as a Cake Tool

LaquaiLib.Threading.CronTimer

A PeriodicTimer-like timer driven by one or more cron expressions instead of a fixed interval. Backed by Cronos for ultra-fast, lightweight cron parsing.

Overview

CronTimer fires at the next occurrence dictated by any of the provided cron expressions. When multiple expressions are supplied the timer fires at whichever is earliest. Both standard 5-field (min hour dom mon dow) and 6-field (sec min hour dom mon dow) expressions are accepted when constructing from strings.

Like PeriodicTimer, only a single WaitForNextTickAsync call may be in flight at any time. Disposing the timer wakes any pending waiter with false.

Building

dotnet build

Testing

dotnet test

Packaging

The library automatically generates a NuGet package on Release builds:

dotnet build -c Release

The generated .nupkg and .snupkg (symbols) files can be found in bin/Release/.

Installation

dotnet add package LaquaiLib.Threading.CronTimer

Or from a local build:

dotnet nuget add source ./bin/Release --name local
dotnet add package LaquaiLib.Threading.CronTimer

Usage

Basic loop — fires every minute

using LaquaiLib.Threading.CronTimer;

using var timer = new CronTimer("* * * * *");

while (await timer.WaitForNextTickAsync())
{
    // executed once per minute
}

6-field expression — fires every second

using var timer = new CronTimer("* * * * * *");

Multiple expressions — fires at the earliest occurrence

// fires at :00 and :30 of every hour
using var timer = new CronTimer("0 * * * *", "30 * * * *");

Pre-parsed CronExpression objects

When constructing from CronExpression instances the expressions may use different formats (5-field and 6-field can be mixed freely):

using Cronos;

var everySecond = CronExpression.Parse("* * * * * *", CronFormat.IncludeSeconds);
var everyMinute = CronExpression.Parse("* * * * *",   CronFormat.Standard);

using var timer = new CronTimer(everySecond, everyMinute);

Custom time zone

var tz = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
using var timer = new CronTimer(tz, "0 9 * * 1-5"); // 09:00 Mon–Fri Eastern

Cancellation and disposal

WaitForNextTickAsync accepts a CancellationToken. The method returns false (without throwing) when the timer is disposed; it throws OperationCanceledException when the token is cancelled.

using var cts = new CancellationTokenSource();

using var timer = new CronTimer("* * * * *");

while (await timer.WaitForNextTickAsync(cts.Token))
{
    // ...
}

License

Unlicense

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 109 3/19/2026