BackgroundTaskExecutor 11.0.0

dotnet add package BackgroundTaskExecutor --version 11.0.0
                    
NuGet\Install-Package BackgroundTaskExecutor -Version 11.0.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="BackgroundTaskExecutor" Version="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BackgroundTaskExecutor" Version="11.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BackgroundTaskExecutor" />
                    
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 BackgroundTaskExecutor --version 11.0.0
                    
#r "nuget: BackgroundTaskExecutor, 11.0.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 BackgroundTaskExecutor@11.0.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=BackgroundTaskExecutor&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BackgroundTaskExecutor&version=11.0.0
                    
Install as a Cake Tool

BackgroundExecutor

Setting Up

  1. Add .AddBackgroundTaskExecutor()
  2. Specify EF Core provider for inner DbContext using .WithDatabase(options => { })
  3. Call .Use method to finish DI specification
  4. Add section to your appsettings.json

"BackgroundTaskExecutor": {     "Profiles": {         "{profileName}": {             "Interval": {interval},             "IntervalTimeUnit": {"Millisecond" | "Second" | "Minute" | "Hour" | "Day" },             "FirstRunAfter": {delay},             "FirstRunAfterTimeUnit": {"Millisecond" | "Second" | "Minute" | "Hour" | "Day" },             "LeaseDuration": {duration, optional, 2 minutes by default},             "LeaseDurationTimeUnit": {"Millisecond" | "Second" | "Minute" | "Hour" | "Day" },         }     } }

You can override Default profile as well both defining profile with name "Default" or define necessary parameters in "BackgroundTaskExecutor" section

Usage

  1. Add [BackgroundExecution({profileName})] attribute to method
    Please note that BackgroundExecutor uses DI to get class instance for method running and can pass only CancellationToken to executing method

Several instances

Every instance of the application runs the timers, and each job runs on one of them at a time. A job's lease (the SyncLeases table, one row per job and profile) is taken with a single conditional update: only when nobody holds it and the interval has passed since the job last finished. The holder renews it every quarter of LeaseDuration while the job runs and gives it back when the job ends, so:

  • a job that runs longer than its interval never runs on two instances at once;
  • an instance that dies mid-run blocks the job only until its lease expires (LeaseDuration), and an instance that is stopped gives it back at once;
  • a run that loses its lease (it could not renew in time and another instance took over) is cancelled.

The interval is measured from the end of the last run on any instance. The job is identified by its type, method and profile, so two jobs that only share a method name no longer block each other. Upgrading from an earlier version starts each lease from the job's last run in SyncEntries, which is still written as the run log.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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
11.0.0 111 11/11/2026
10.0.14 448 11/2/2026
10.0.13 261 10/25/2026
10.0.3 1,137 2/19/2026
10.0.0 896 11/12/2025
9.0.3 2,043 3/18/2025
9.0.0 1,417 11/20/2024
8.2.0 303 11/5/2024
8.1.1 221 11/5/2024
8.1.0 277 4/26/2024
8.0.2 317 4/18/2024
8.0.1 264 4/18/2024 8.0.1 is deprecated because it has critical bugs.
8.0.0 279 4/10/2024 8.0.0 is deprecated because it has critical bugs.

A job runs on one instance at a time: a lease per job, renewed while it runs and given back when it ends