164 questions
0
votes
0
answers
36
views
backgroundservice rabbitmq consumer waiting
I am implementing an aspnet backgroundservice rabbitmq consumer that subscribes to push events from the server:
protected override async Task ExecuteAsync(
CancellationToken stoppingToken)
{
...
0
votes
1
answer
56
views
Website timeout issue when running two identical background services .NET Core
I am running two identical background services, their only job is to pull from azure sub and send to API. I am pasting one below for the other one only the name changes and values for apiUrl, ...
0
votes
0
answers
135
views
CancellationTokenSource+CallBackNode Memory Leaks (10 MB/minutes)
I have console application for quartz.net operations.
Its basically settings serilog options, loading IJob implemented business logics dll's, creating token source then starting host environment:
...
0
votes
1
answer
355
views
How to inject a hosted service when it also implements other interface [duplicate]
I have the following interface in my .NET Core web application:
public interface IIntegrationManagerService : IHostedService
{
Task<List<IFunciones>> GetFunctionList();
}
The ...
1
vote
1
answer
934
views
Azure Function or Background Service[Background tasks with hosted services] which is more cost affective?
I have some requirements for using some back ground process.
I have 2 option #
Time Trigger Function
Background Service [Background tasks with hosted services]
which one is more cost affective?
I ...
1
vote
0
answers
160
views
What is the prescribed methodology for integrating Wolverine framework within a HostedService?
So far I have been using
MediatR.Courier
for subscribing to messages in my background services / asp.net hosted services.
Why, because Hosted services are singletons, and NotificationHandler are not,...
0
votes
1
answer
213
views
Windows Service - try running until run successfully
I have an Windows Service, that connects to database. If database is not accesable it throws exception and stops. I want it to try and run this service in loop, until it is started succesfully (maybe ...
0
votes
0
answers
270
views
Scaling Dotnet Core Hosted Service That Heavily Modifies Database Records
I have a hosted service that executes a job/function periodically (a minute after execution). That job reads possibly millions of data and checks if needs to be modified by reading some data from the ...
1
vote
2
answers
2k
views
Run multiple task in background service in .NET Core with different timer duration
I'm using the BackgroundService - is it possible to have multiple task in one background service project in .NET Core with different timer duration:
FirstLoop - execute every second
SecondLoop - ...
3
votes
1
answer
426
views
Allow user to cancel task running in BackgroundService
I created a background service to process items in a queue as demonstrated here:
Queued Background Task
Unlike the example, items are added to the queue via a Web API method that looks something like ...
1
vote
0
answers
1k
views
When to use .NET Generic Host's Run, Start and WaitForShutdown
I use the .NET Generic Host (to run a BackgroundService). All the examples I've seen (example) use host.Run[Async], so I use that and it works for me.
However there are a number of related lifetime ...
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 ...
0
votes
1
answer
461
views
Getting Dependency Injection of a hosted service
I have the following code:
builder.Services.AddSingleton<IAvailabilityWorker, AvailabilityWorker>();
builder.Services.AddHostedService<AvailabilityWorker>();
There is a timer in the ...
0
votes
0
answers
104
views
Hubconnection does not update data received from signalr server
On server I use background service + SignalR hub to send time to all clients. Client-side is written using Winforms.
The server is sending correct data to client: (check log)
Worker running at: ...
2
votes
1
answer
241
views
IHostedService in C# doesn't trigger method every time?
This is my code in .net core 5 which wants to trigger a function every 2 minutes. I don't know why LoadData function doesn't get triggered after 2 minutes and only get triggered the first time?
public ...
0
votes
0
answers
99
views
blazor webassembly hosted authenticate UI not user
I am trying to set up a form with blazor webassembly and asp.net core hosted. I'm using .Net 7.
The form in client side sends the data entered by an unknown user to the api server side.
No user ...
1
vote
1
answer
570
views
Hosted Service scope when running as Azure Web Job
Working on a BackgroundService that is published to Azure as a Web Job, I noticed something strange (works fine on Azure, exception when running locally), so I tried to recreate the situation.
Program....
0
votes
1
answer
424
views
How to change URL of a Blazor server app that hosted as a windows service
I've a Blazor server app that is installed as windows service and runs fine. The default application URL is "http://localhost:5000" and I want to configure it so that it could be rechable ...
0
votes
1
answer
2k
views
How can I troubleshoot my ASP.NET Core hosted service not working?
Problem with trying to add the Hosted Service to the Application
I'm trying to add Hosted Service to my application, but it seems not to work at all (In debug none of its methods were called).
Here is ...
3
votes
3
answers
9k
views
How to map environment variables to a config object in a IHostedService?
I'm creating a new console app for the first time in a while and I'm learning how to use IHostedService. If I want to have values from appsettings.json available to my application, the correct way now ...
1
vote
2
answers
199
views
Is it ok to return CompletedTask from BackgroundService.ExecuteAsync?
I have the following two alternatives:
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
_ = ForeverRunningLoop(stoppingToken);
return Task.CompletedTask;
}
private ...
0
votes
1
answer
1k
views
.NET: OpenTelemetry, connect two scopes
I have three services running on .NET with OpenTelemetry tracing enabled. Communication begins from the first service to the second one via HttpClient. The second service handles an HTTP request and ...
2
votes
1
answer
2k
views
OpenTelemetry and hosted services
I have a .NET 6 web application with HostedServices doing background processing. When the HostedService starts Activity just after the application starts, this Activity is not exported by the ...
3
votes
1
answer
655
views
Is there a way I can call a method from a class that is injected through dependency injection, right after the startup in azure function?
I have an azure function whose startup looks like this
internal class Startup : FunctionsStartup
{
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
...
0
votes
0
answers
103
views
How to subscribe a hosted (background) service to a Hub as a client?
The Problem:
How to establish a hosted service (background service) which can receive, process and send messages from a signalR hub?
The story:
Step 1. Client #1 runs a blazor (server-side) App. The ...
0
votes
1
answer
93
views
Long running service for scheduled jobs in .NET 6
I will be using .NET 6 for a project that will execute scheduled jobs. I don't want to run the service as a Windows or Linux service. No while loop or Task.Delay hack should be used. I'm planning to ...
2
votes
1
answer
2k
views
Requesting for application to stop during IHostedService.StartAsync results in an unhandled TaskCanceledException
I have an IHostedService which will use IHostApplicationLifetime.StopApplication if it fails during StartAsync. At first I thought I had missed out exception catching somewhere in my code when a ...
1
vote
0
answers
435
views
.NET 6 attach to windows session switch
I am migration an app from .NET Framework to .NET 6. It starts Kestrel web server internally and it is intended to run as a Windows Service - in the old version that was achieved using Topshelf ...
1
vote
1
answer
652
views
How to create Global Variable per hosted service in .Net core
How to create a global variable that can be unique per hosted service execution?
Complete Code:
https://github.com/matvi/dotnet-hosted-services
The problem:
When running hosted services is difficult ...
0
votes
1
answer
2k
views
Azure Service Bus not all messages received in hosted service web app
Inside a .net web app, I set up a hosted service to receive messages from an Azure Service Bus topic. The problem is that not all messages are received, only an arbitrary amount (e.g. of 20 messages ...
0
votes
0
answers
144
views
How can I expose data from hosted service to a streaming endpoint on interval
At the moment I have .NET Core Web API running on a Raspberry Pi, the job of this API is to collect data from a connected device on an interval and save the data to a DB, which is what it does already....
2
votes
0
answers
243
views
Multiple .NET Core service instances on Docker, AddHostedService issues
I'm running .NET Core 5.0 services on Docker, sometimes with multiple instances of the same service.
Some of the services have "Hosted Services" registered in their Startup.cs file.
However, ...
2
votes
1
answer
11k
views
Multiple Background Services in .NET Core
Create Multiple Background tasks in .NET 6 which are independent to each other in functionality aspect and runs parallelly / simultaneously depending on the scheduled timings.
With Worker class ...
1
vote
1
answer
352
views
What is the difference between instantiating DbContext and Getting DbContext service with IServiceScopeFactory in a hosted service
I wanted to create a background task for my application and in that task I need DbContext to do some operation on data for every 5 seconds.I tried 2 way to get DbContext and it seems like both of them ...
2
votes
1
answer
2k
views
IHostedService mirgrated from .Net Core 3.1 to .Net 6 stops working
Background services deployed as Windows Services stopped working. It happened after we migrated from .Net core 3.1 to .Net 6. Services are created using IHosted Service. Services are type of Time ...
2
votes
0
answers
2k
views
Possible to have hosted services running on there own thread?
I noticed HostedServices are ran in a single threaded Async mode. Is it possible to have each hosted service running on its own thread? I am having several hosted services running, for testing ...
1
vote
0
answers
1k
views
Checking the status of an IHostedService from another project?
I'm currently working on a project which processes files via a Hosted Service background task, persists those files to a DB, then show the user that data via a webpage. The webpage and the background ...
8
votes
2
answers
11k
views
IHostedService .NET 6 not starting when deployed
I have an API which contains a HostedService that is built in VS2022 with .Net 6.
When I run locally the service is called as expected and everything works fine but when deplyed, the service doesn't ...
0
votes
1
answer
2k
views
Application insight not receiving Nlog for hosted service
I try everything I can think of but I must miss something.
I have a hostedService project in netcoreapp3.1
I referenced the following
<PackageReference Include="Microsoft.ApplicationInsights....
22
votes
2
answers
24k
views
Run async hosted service every 5 minutes in ASP.NET Core
The ASP.NET Core docs for background services show a number of implementation examples.
There's an example for starting a service on a timer, though it's synchronous. There's another example which is ...
0
votes
1
answer
421
views
How to serve endpoint from docker file?
I am having .net a self-hosted application, basically, it runs for 12 hours. The entire functionality is working as expected in my local machine.
Reference:
Background tasks with hosted services in ...
1
vote
1
answer
2k
views
IHostedService not running on IIS 10
I have a ASP.NET Web-API which has a IHostedService to periodically execute a specific Task (fetch data from another website and write it to the Database).
This works well on IIS-Express (starting ...
16
votes
2
answers
62k
views
'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType:IHostedService
I am using .NET 5 and I want to run a background task using IHostedService classess as you can see:
public class PasargadJobs : IHostedService, IDisposable
{
private Timer _timer = null!;
...
1
vote
1
answer
2k
views
Only one usage of each socket address (protocol/network address/port) is normally permitted when AppPool is recycled
I have a .net Core application hosted on IIS.
The application initializes WebSocketServer, by adding a wrapper class as a HostedService.
The hosted service execute the Start() method seen below on its ...
0
votes
0
answers
618
views
Background parallel tasks
I have an console application .NET core which uses Background tasks with hosted services like described here : link
I've used the code sample provided by Microsoft and added the IBackgroundTaskQueue, ...
1
vote
0
answers
636
views
In C#, what could cause a hosted service to be canceled and what is the best way to recover?
We have a hosted service which transcribes data from the Azure Service Bus to another microservice. Aside from putting data in a Queue on the service bus, there is no opportunity for a human to ...
14
votes
4
answers
8k
views
.NET Core stop HostedService in the Integration test
I have .NET Core web API project, for some reasons, we created a background service in this project and start running the background service while the application is started.
So, we created a ...
2
votes
1
answer
2k
views
Is there an easier way to pass an array as command line argument using Microsoft.Extensions.Configuration?
I am working on a .net generic host app and I would like to pass some configuation via command line and then bind it to an object:
public class CommandArgs
{
public string Mode { get; set; }
...
0
votes
1
answer
1k
views
C# and ASP.NET MVC : BackgroundService problems
I got some problems with HostedService / background classes in my ASP.NET MVC project.
What I need is a timer that process some functions every X seconds and when those functions reach goals, go to ...
1
vote
2
answers
494
views
Eager loading doesn't work with BackgroundService
I'm trying to load related entities in a console application that runs a BackgroundService,
but it doesn't load related entities, I have had this problem for hours now and I just noticed it happens ...