if the background service is in the same application, then just use a shared collection (queue):
BackgroundService - Is it possible to set parameter value?

Cenk
766
Reputation points
Hi,
I have a background service. I wonder if it is possible to set a parameter to this service from the Blazor Server application or in any other way?
Thank you in advance.
{count} votes
I actually want to set the periodic timer externally, not manually in the worker.
Try to store the timer timespan in the configure file (appsettings.json) file or database, then when start the background service get the timespan and use it. In this scenario, you can edit the timer timespan in the configure file or database.
Do I have to restart the worker every time I change the timespan?
Yes, you have to restart the worker.
Besides, you can refer to Edward's reply in this thread to start/stop the worker manually:
ASP.NET Core IHostedService manual start/stop/pause(?)
Sign in to comment