95 questions
0
votes
2
answers
97
views
How to inject a reference to a specific IHostedService into another (dependant) IHostedService?
I have a .NET 4.7.2 console application that uses .NET Generic Host and has 2 background services. One of them (dependent) should start its work only after another one (base) has completed its ...
1
vote
0
answers
153
views
How to leverage IOptions in .NET Aspire and have them passed in from the AppHost
I am discovering .NET Aspire and trying to migrate a solution to it. In the solution, I have several Worker applications that are using the HostApplicationBuilder with HostedServices.
Initially these ...
0
votes
0
answers
63
views
.NET 8 application file written gets lost after a while
I have a .NET 8 application which, among other things, has the following functionality: it contains a hosted service that fetches some records from a database, produces some .txt files and writes them ...
0
votes
1
answer
284
views
AddSingleton and AddHostedService in WebAPI application
In my application I have some services to manage some devices on a PC (mainly via serial ports). Services will be accessed through API controllers.
Each service must run as singleton (single instance) ...
0
votes
3
answers
212
views
How to let HostedService run after host started?
I have a .NET 6 console app.
Program.cs code:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Threading;
using ...
0
votes
1
answer
144
views
System.AggregateException when run program.cs on .NET 8.0
I'm trying to implement email background service based on IHostedService.
But I get this error:
System.AggregateException: 'Some services are not able to be constructed (Error while validating the ...
1
vote
0
answers
68
views
How do I inject dependencies on Hangfire Job initiated by BackgroudService?
I have a .net Project which needs to run custom logic on Cron.
Here's my Code:
builder.Services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel....
0
votes
0
answers
28
views
IHostedService Manager C# .net6
I have a .NET 6 project with a large number of classes that inherit from IHostedService. All of them receive two input parameters: Config config and LogManager logManager. Are there any ready-made ...
2
votes
1
answer
270
views
How to add data seed method with IHostedService
This is my Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddTransient<DatabaseSeeder>();
builder.Services.AddScoped<...
1
vote
2
answers
556
views
Post-Build Addition of IHostedService
Is it possible to add an IHostedService to an IHost after calling HostApplicationBuilder.Build() and IHost.StartAsync()?
The application needs to be able to load plug-ins during use and have services ...
1
vote
3
answers
2k
views
Return non-zero exit code for crashed .NET Core BackgroundService
Due to bugs in BackgroundService I'm using Stephen Cleary's excellent workaround. It works, but I can't return a non-zero exit code upon failure.
A minimal working example (for use with the $ dotnet ...
1
vote
0
answers
82
views
Trouble with Running a Continuous Task in the Background
I want to add notifications at certain intervals using BackgroundService, but the waiting interval I set is 10 seconds in this example, the program running ends when it is finished.
Service like this:
...
1
vote
1
answer
2k
views
Is the difference between AddQuartz and AddQuartzHostedService that the latter adds a hosted service?
I'm just learning Quartz.NET (and C# in general in fact) and I'm struggling to get my head around the differences between the AddQuartz and AddQuartzHostedService methods. From what I've seen here, ...
0
votes
0
answers
370
views
Is It OK to Instantiate Multiple Instances of the Generic Host (IHost)
We have a framework upon which my team builds microservice apps and related jobs. We want to migrate it from using IWebHost for web apps and IHost for jobs to simply using IHost for both. We haven't ...
0
votes
1
answer
922
views
How To Get The Results Of A Worker Background Service In C# .NET?
I have used the Worker Service template generated by Visual Studio 2022 as an example, but basically I was wondering what would be a method for finding out the result of a worker run once it is ...
0
votes
1
answer
511
views
Ho to get an asp.net hosted service to run automatically on IIS 10?
I'm having trouble with getting my hosted service to run automatically (without a user initiating a request) on IIS 10.
This is an asp.net app, .NET 7 with a React front-end. It's running Signal R and ...
1
vote
1
answer
622
views
How to prevent .net 6 generic hosted console apps logging queue from being shutdown on application stop?
I'm currently working on a small demo project for a dotnet console application using the generic hosting for logging and configuration. In the context of writing this demo / proof of concept app I ran ...
0
votes
1
answer
696
views
Long-running task without IHostedService running the entire life of the application?
I have a website page that needs the option of performing an operation that could take several minutes. To avoid performance issues and time outs, I want to run this operation outside of the HTTP ...
1
vote
1
answer
459
views
How can I run an IHostedService separate from the WebApplication (WebApi)?
Suppose I have a number of IHostedService implementations with a ton of dependencies that no WebApi controllers do not have direct nor indirect dependencies, too.
Ideally, I like it if could set up an ...
0
votes
0
answers
213
views
How to run background task? keep getting System.AggregateException
This is my program.cs
using TestEmailTaskScheduler.Controllers;
using TestEmailTaskScheduler.Models;
using System.Configuration;
var builder = WebApplication.CreateBuilder(args);
// Add services to ...
5
votes
2
answers
4k
views
.NET OpenTelemetry Not Adding Listener For ActivitySource
Why is OpenTelemetry .NET not adding a listener for my ActivitySource in a hosted service on generic host?
I have some configurations to pass into OpenTelemetry set-up, so I depend on a class MyClass. ...
5
votes
2
answers
5k
views
BackgroundService never started/stopped if no await done
On ASP.NET Core I'm observing a strange behavior, that was actually reported in BackgroundService not shutting down, stoppingToken never set with .net core generic host but without the root cause ever ...
0
votes
0
answers
169
views
Ensure finalizing iHostedServices before recycling on a IIS with dotnet core
I have a dotnet 6 application with an hosted service that runs some scheduled tasks all x-minutes. So far so good, everything working almost perfectly. What I get from time to time is, that the app ...
2
votes
0
answers
687
views
Quart.Net :Enable/Disable the job at RunTime
i have done similar Thing in my Project https://andrewlock.net/using-quartz-net-with-asp-net-core-and-worker-services/. i am scheduling all the job at the StartAsync by fetching the job data from Db . ...
2
votes
1
answer
6k
views
Cannot consume scoped service 'ApplicationDbContext' from singleton 'Microsoft.Extensions.Hosting.IHostedService'
I'm using .Net Core Background Service to Connect to Kafka and save messages to SQL Server. My Project Structure looks like this:
In the Infrastructure Dependency, I have the following code to ...