Closed saisworld closed 5 years ago
StartAsync is intended to be non-blocking. Schedule any work you need to and then let StartAsync finish. It's waiting for the first one to finish starting before it tries to start the next one.
@Tratcher I believe Backgroundservices /IHostedService is intended for the long running jobs. If it has to finish off the work then its no longer a long backgroundservice service.
Or .Net core doesnt allow running multiple backgroundservices using IHostedservice
The background service doesn't need to complete, only the StartAsync method. Here's one example where you override ExecuteAsync, not StartAsync. In that example it's still important that ExecuteAsync is actually async or it can block StartAsync.
Thanks Tratcher. that did the trick.
Hi,
I'm trying to activate two background services both implementing IHostedService interface. However, during runtime only one gets activated. The first service that was registered in the startup.cs gets activated. Please advise.
public class BackgroundServiceClass2 : IHostedService {
Second Ihostedservice -
` public class BackgroundServiceClass : IHostedService {
In my startup.cs,I have registered like this -
services.AddHostedService<BackgroundServiceClass>(); services.AddHostedService<BackgroundServiceClass2>();