The right way of hosting worker threads on each rounded hour RRS feed

  • Question

  • User-375835195 posted


    I'm making an application which is supposed to have multiple threads/services (bots) running. Those threads are supposed to check an API for current currency values. There will be some calculations on each rounded hour (e.g. 10:00, 11:00, etc).

    Currently, I'm running Angular (front-end) and ASP.NET Core 2.2 MVC + SignalR (back-end).

    What's the right way of hosting those threads/services? Assuming those threads are spawned based on database records.

    I was looking at https://docs.microsoft.com/en-us/aspnet/core/signalr/background-services?view=aspnetcore-2.2 but I'm not quite if that's the right solution since I have to display the results in the front-end with SignalR if they match to certain conditions.

    What's the right way of doing that scenario?

    Tuesday, August 13, 2019 9:02 AM


  • User-474980206 posted

    when using background services, you use Scope when you are using DI and you need a new instance. This is unrelated to the scope created for web requests. 

    you should be looking at the queued sample. your signal/r client should queue a timer request. the background process should be running on a timer. every time it hits the clock cycle, it should check the queue / collection and process the queue / collection (starting threads if required). you will then need a determine when to stop processing and remove the queue / collection.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2019 5:14 PM

All replies