Imato.Services.RegularWorker
3.6.0
dotnet add package Imato.Services.RegularWorker --version 3.6.0
NuGet\Install-Package Imato.Services.RegularWorker -Version 3.6.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="Imato.Services.RegularWorker" Version="3.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Imato.Services.RegularWorker" Version="3.6.0" />
<PackageReference Include="Imato.Services.RegularWorker" />
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 Imato.Services.RegularWorker --version 3.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Imato.Services.RegularWorker, 3.6.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 Imato.Services.RegularWorker@3.6.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=Imato.Services.RegularWorker&version=3.6.0
#tool nuget:?package=Imato.Services.RegularWorker&version=3.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Imato.Services.RegularWorker
Create long running services and workers
- Create new worker Override ExecuteAsync in RegularWorker
// Worker.cs
using Imato.Services.RegularWorker;
public class Worker : RegularWorker
{
public Worker(IServiceProvider provider) : base(provider)
{
}
// Add same work in ExecuteAsync method
public override async Task ExecuteAsync(CancellationToken token)
{
await SendHelloAsync();
}
}
- Add worker to DI Simple. All your workers started automatically.
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args);
appBuilder.ConfigureWorkers(args);
Or manualy
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddSingleton<IHostedService, Worker>();
})
Start one worker as microservise from all your workers pool.
>myworker.exe
- Start workers
// Program.cs
using Imato.Services.RegularWorker;
var app = appBuilder.Build();
// All
app.StartAppAsync();
// Or single worker
await app.StartAppAsync(");
- Configure worker
appsettings.Example.json
{
"Workers": {
"LogWorker": {
"StartInterval": 15000,
"RunOn": "EveryWhere",
"Enabled": true
}
}
}
RunOn: PrimaryServer, SecondaryServer, SecondaryServerFirst, EveryWhere.
Or configure throw field settings in Workers DB table.
Using Log table in MS SQL server
Add configuration for DbLogger: ConnectionString, Table and table Columns
// appsettings.json
{
"ConnectionStrings": {
"mssql": "Data Source=localhost;Initial Catalog=TestDb;Persist Security Info=True;User ID=test;Password=test;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
},
"DbLogger": {
"Options": {
"ConnectionString": "Data Source=localhost;Initial Catalog=TestDb;Persist Security Info=True;User ID=test;Password=test;",
"Table": "dbo.Logs",
"Columns": "[Date], [User], [Level], [Source], [Message], [Server]"
}
}
}
}
Add logger in DI config
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args)
.ConfigureDbLogger();
.ConfigureServices(services =>
{
services.AddSingleton<IHostedService, LogWorker>();
});
// Start LogWorker and other workers
var app = appBuilder.Build();
app.StartServices();
await app.RunAsync();
or shortly configure workers
// Program.cs
using Imato.Services.RegularWorker;
var appBuilder = Host.CreateDefaultBuilder(args);
appBuilder.ConfigureWorkers();
Monitoring
View actual workers status in different apps and hosts
select id, name, host, appName, date, settings, active from dbo.workers
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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.
-
net9.0
- Imato.Dapper.DbContext (>= 1.16.0)
- Imato.Logger.Extensions (>= 1.3.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Hosting (>= 9.0.9)
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 |
|---|---|---|
| 3.6.0 | 257 | 10/1/2025 |
| 3.3.0 | 198 | 7/18/2025 |
| 3.2.2 | 285 | 3/19/2025 |
| 3.2.1 | 234 | 12/5/2024 |
| 3.2.0 | 229 | 10/25/2024 |
| 3.1.1 | 198 | 10/15/2024 |
| 3.0.2 | 242 | 8/29/2024 |
| 3.0.0 | 246 | 6/21/2024 |
| 2.18.0 | 231 | 5/15/2024 |
| 2.17.4 | 289 | 3/6/2024 |
| 2.17.3 | 310 | 1/25/2024 |
| 2.17.2 | 242 | 1/24/2024 |
| 2.17.1 | 230 | 1/23/2024 |
| 2.17.0 | 271 | 1/17/2024 |
| 2.16.9 | 305 | 12/28/2023 |
| 2.16.8 | 268 | 12/28/2023 |
| 2.16.6 | 283 | 12/28/2023 |
| 2.16.5 | 253 | 12/28/2023 |
| 2.16.4 | 265 | 12/27/2023 |
| 2.16.0 | 233 | 12/20/2023 |
Loading failed
Ready to use