NCronJob 4.12.2
See the version list below for details.
dotnet add package NCronJob --version 4.12.2
NuGet\Install-Package NCronJob -Version 4.12.2
<PackageReference Include="NCronJob" Version="4.12.2" />
<PackageVersion Include="NCronJob" Version="4.12.2" />
<PackageReference Include="NCronJob" />
paket add NCronJob --version 4.12.2
#r "nuget: NCronJob, 4.12.2"
#:package NCronJob@4.12.2
#addin nuget:?package=NCronJob&version=4.12.2
#tool nuget:?package=NCronJob&version=4.12.2
<h1 align="center">NCronJob</h1>
<p align="center"> <img src="/assets/logo_small.png" alt="logo" width="120px" height="120px"/> <br> <em>Scheduling made easy</em> <br> </p>
NCronJob
A Job Scheduler sitting on top of IHostedService in .NET.
Often, one finds oneself between the simplicity of BackgroundService/IHostedService and the complexity of
a full-blown scheduler like Hangfire or Quartz.
This library aims to fill that gap by providing a simple and easy-to-use job scheduler that can be used in any .NET
application and feels "native".
There's no need to set up a database - just schedule your tasks right away! The library provides two ways of scheduling jobs:
- Instant jobs - Run a job immediately (or with a small delay, or at a specific date and time).
- Cron jobs - Schedule a job using a cron expression.
The whole documentation can be found here: NCronJob Documentation
If you are new to the project, start with:
llms.txtfor machine-friendly discovery
Features
- The ability to schedule jobs using a cron expression.
- The ability to instantly run a job.
- Parameterized jobs - Instant as well as cron jobs!
- Integration with ASP.NET - Access your DI container like you would in any other service.
- Get notified when a job is done (either successfully or with an error).
- Retries - If a job fails, it will be retried.
- The job scheduler supports TimeZones. Defaults to UTC time.
- Minimal API for Jobs - Implement jobs in a one-liner.
- Startup jobs - Run a job when the application starts.
- Define job dependencies - trigger another job if one was successful or faulted!
- Add, remove, and update jobs at runtime.
- Observe the progress of a job's execution.
Not features
As this is a simple scheduler, some features are not included by design. If you need these features, you might want to
look into a more advanced scheduler like Hangfire or Quartz.
- Job persistence - Jobs are not persisted between restarts of the application.
- Job history - There is no history of jobs that have been run.
Choose your starting point
- Use the Minimal Job API when you want the smallest setup and delegate-based jobs
- Use
IJobimplementations when you want reusable job types, notification handlers, or richer orchestration - Use named jobs when you need runtime management or multiple registrations of the same job type
- Use startup jobs when work must run during application startup
Working samples live in:
For the generic-host examples below, use an ASP.NET app, a worker service, or another project that already references Microsoft.Extensions.Hosting.
Short example
There are two ways to define a job.
Minimal Job API
You can use this library in a simple one-liner:
builder.Services.AddNCronJob((ILoggerFactory factory, TimeProvider timeProvider) =>
{
var logger = factory.CreateLogger("My Anonymous Job");
logger.LogInformation("Hello World - The current date and time is {Time}", timeProvider.GetLocalNow());
}, "*/5 * * * * *");
await builder.Build().RunAsync();
With this simple lambda, you can define a job that runs every 5 seconds. Pass in all dependencies, just like you would with a Minimal API.
Via the IJob interface
- Import the namespace (or let your IDE do the dirty work)
using NCronJob;
- Create a job
public class PrintHelloWorld : IJob
{
private readonly ILogger<PrintHelloWorld> logger;
public PrintHelloWorld(ILogger<PrintHelloWorld> logger)
{
this.logger = logger;
}
public Task RunAsync(IJobExecutionContext context, CancellationToken token)
{
logger.LogInformation("Hello World");
logger.LogInformation("Parameter: {Parameter}", context.Parameter);
return Task.CompletedTask;
}
}
- Register the NCronJob and the job in your
Program.cs
builder.Services.AddNCronJob(options =>
options.AddJob<PrintHelloWorld>(j =>
{
// Every minute and optional parameter
j.WithCronExpression("* * * * *")
.WithParameter("Hello World")
.WithTimeout(TimeSpan.FromMinutes(2))
.WithJobRunExpiry(TimeSpan.FromMinutes(5));
}));
Scheduler-wide concurrency and queued-run expiry can be configured on the outer builder. By default, concurrency is
Environment.ProcessorCount * 4, job execution has no timeout, and queued runs expire after ten minutes.
Timeout.InfiniteTimeSpan disables either timeout or expiry.
builder.Services.AddNCronJob(options => options
.WithMaxDegreeOfParallelism(16)
.WithDefaultJobRunExpiry(TimeSpan.FromMinutes(15))
.AddJob<PrintHelloWorld>());
- Run your application and see the magic happen!
When to call UseNCronJobAsync
Call UseNCronJobAsync() or UseNCronJob() when you register startup jobs via RunAtStartup(...).
using Microsoft.Extensions.Logging;
using NCronJob;
var builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);
builder.Services.AddNCronJob(options =>
{
options.AddJob<MyJob>(j => j.RunAtStartup());
});
var app = builder.Build();
await app.UseNCronJobAsync();
await app.RunAsync();
public sealed class MyJob(ILogger<MyJob> logger) : NCronJob.IJob
{
public Task RunAsync(NCronJob.IJobExecutionContext context, CancellationToken token)
{
logger.LogInformation("Startup job executed.");
return Task.CompletedTask;
}
}
Regular recurring jobs and instant jobs do not require this call.
Samples and detailed docs
Detailed feature docs:
- Getting Started
- Define and Schedule Jobs
- Triggering instant jobs
- Model Dependencies
- Dynamic Job Control
- Known gotchas
Sample applications:
Triggering an instant job
If the need arises and you want to trigger a job instantly, you can do so:
public class MyService
{
private readonly IInstantJobRegistry jobRegistry;
public MyService(IInstantJobRegistry jobRegistry) => this.jobRegistry = jobRegistry;
public void MyMethod() => jobRegistry.RunInstantJob<MyJob>("I am an optional parameter");
// Alternatively, you can also run an anonymous job
public void MyOtherMethod() => jobRegistry.RunInstantJob((MyOtherService service) => service.Do());
}
Support & Contributing
Thanks to all contributors and people who are creating bug reports and valuable input:
<a href="https://github.com/NCronJob-Dev/NCronJob/graphs/contributors"> <img src="https://contrib.rocks/image?repo=NCronJob-Dev/NCronJob" alt="Supporters" /> </a>
If you have any questions or suggestions, feel free to open a new issue or pull request. Do you want to contribute? Great! We have a predefined codespace for you to get started right away! With that you don't need any local setup and can start right away! Either coding or updating the documentation - everything is set and done for you!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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 is compatible. 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. |
-
net10.0
- Cronos (>= 0.13.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.11)
- Polly (>= 8.7.0)
-
net8.0
- Cronos (>= 0.13.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Polly (>= 8.7.0)
-
net9.0
- Cronos (>= 0.13.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.19)
- Polly (>= 8.7.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NCronJob:
| Package | Downloads |
|---|---|
|
Avolutions.Baf.Core
Core library for the Avolutions Business Application Framework (BAF). |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on NCronJob:
| Repository | Stars |
|---|---|
|
linkdotnet/Blog
A blog (engine) completely written in C# and Blazor. It aims to be a simple use and easy to extend platform. Blogposts are written in Markdown and are rendered to HTML. This gives all the flexibility needed to express yourself but also have an easy way of creating posts in the first place.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.12.3 | 54 | 9/25/2026 |
| 4.12.2 | 38 | 9/25/2026 |
| 4.12.1 | 682 | 9/17/2026 |
| 4.12.0 | 149 | 9/17/2026 |
| 4.11.0 | 665 | 9/11/2026 |
| 4.10.3 | 134 | 9/11/2026 |
| 4.10.2 | 17,571 | 6/8/2026 |
| 4.10.1 | 12,397 | 3/31/2026 |
| 4.10.0 | 404 | 3/30/2026 |
| 4.9.0 | 5,915 | 12/28/2025 |
| 4.8.1 | 424 | 12/28/2025 |
| 4.8.0-preview | 145 | 12/27/2025 |
| 4.7.0 | 4,946 | 11/22/2025 |
| 4.7.0-preview | 146 | 12/27/2025 |
| 4.6.0 | 14,415 | 9/2/2025 |
| 4.5.4 | 7,637 | 6/14/2025 |
| 4.5.2-preview | 225 | 6/14/2025 |
| 4.5.1-preview | 289 | 4/24/2025 |
| 4.5.0-preview | 564 | 4/3/2025 |
| 4.4.1 | 1,897 | 3/27/2025 |
Changes in NCronJob
See the full changelog at https://github.com/NCronJob-Dev/NCronJob/blob/main/CHANGELOG.md