ScheduledServices 1.0.0-preview0.0.13
See the version list below for details.
dotnet add package ScheduledServices --version 1.0.0-preview0.0.13
NuGet\Install-Package ScheduledServices -Version 1.0.0-preview0.0.13
<PackageReference Include="ScheduledServices" Version="1.0.0-preview0.0.13" />
paket add ScheduledServices --version 1.0.0-preview0.0.13
#r "nuget: ScheduledServices, 1.0.0-preview0.0.13"
// Install ScheduledServices as a Cake Addin #addin nuget:?package=ScheduledServices&version=1.0.0-preview0.0.13&prerelease // Install ScheduledServices as a Cake Tool #tool nuget:?package=ScheduledServices&version=1.0.0-preview0.0.13&prerelease
ScheduledServices
This is a simple library that makes it easy to schedule your services. You can schedule a service to run after a delay, or to keep running with some delay between runs.
To implement this, have your service inherit ToggleService, ScheduledService, or RecurringService. You can also override GetDelayBeforeExecutionAsync or GetDelayBetweenExecutionsAsync if you need to compute the delay. The example below shows how to configure your service to run one minute after startup and keep running every minute.
appsettings.json
{
"Services": {
"YourService": {
"Enabled": true,
"DelayBeforeExecution": "00:01:00.0",
"DelayBetweenExecutions": "00:01:00.0"
}
}
Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
.ConfigureScheduledServices((host, scheduledServicesConfiguration) =>
{
scheduledServicesConfiguration.Configuration = host.Configuration;
scheduledServicesConfiguration.Path = "Services:";
})
.ConfigureServices((context, services) =>
{
// schedules a service with no extension methods
services.Configure<YourServiceOptions>(context.Configuration.GetRequiredSection($"Services:{typeof(YourService).Name}"));
.AddSingleton<YourService>()
.AddHostedService(services => services.GetRequiredService<YourService>());
// schedules a service using provided extension methods
services.ConfigureScheduledService<YourService, YourServiceOptions>().AddHostedSingleton<YourService>();
});
Options
public class YourServiceOptions : IRecurringServiceOptions
{
// implement the interface, or inherit RecurringServiceOptions
public TimeSpan DelayBeforeExecution { get; set; }
public TimeSpan DelayBetweenExecutions { get; set; }
public bool Enabled { get; set; }
}
Service
public class YourService : RecurringService
{
public YourService(ILogger<YourService> logger, IOptions<YourServiceOptions> options) : base(logger, options)
{
}
protected override async Task ExecuteScheduledTaskAsync(CancellationToken cancellationToken)
{
// any async work
// errors will be logged
}
protected override ValueTask<TimeSpan> GetDelayBeforeExecutionAsync(CancellationToken cancellationToken)
{
// optionally you can compute the delay here
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. 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. |
-
net5.0
- Microsoft.Extensions.Hosting (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ScheduledServices:
Package | Downloads |
---|---|
CocApi.Cache
Caches response from the Clash of Clans API. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.3 | 1,245 | 10/9/2022 |
1.3.2 | 711 | 10/2/2022 |
1.3.1 | 415 | 10/2/2022 |
1.3.0 | 409 | 9/3/2022 |
1.2.0 | 442 | 5/15/2022 |
1.1.1 | 448 | 5/9/2022 |
1.1.0 | 426 | 5/7/2022 |
1.0.0 | 457 | 1/17/2022 |
1.0.0-preview0.0.13 | 127 | 1/17/2022 |
1.0.0-preview0.0.12 | 136 | 1/17/2022 |
1.0.0-preview0.0.11 | 129 | 1/17/2022 |
1.0.0-preview0.0.10 | 140 | 1/2/2022 |
1.0.0-preview0.0.9 | 141 | 1/1/2022 |
1.0.0-preview0.0.7 | 345 | 12/13/2021 |
1.0.0-preview0.0.6 | 335 | 12/13/2021 |
1.0.0-preview0.0.5 | 324 | 12/13/2021 |
1.0.0-preview0.0.4 | 312 | 12/12/2021 |
1.0.0-preview0.0.3 | 147 | 12/12/2021 |
1.0.0-preview0.0.2 | 132 | 12/12/2021 |
1.0.0-preview0.0.1 | 136 | 12/12/2021 |