Background task any opportunity to have the output in client app?

If that’s the case then you need to make sure things work even when you have more than one client asking for the same ticker, so you shouldn’t start the background task from the client, otherwise you end up with many background tasks running in parallel getting the same ticker value.

I would have:

  1. a table with 3 columns: ticker, the id of the client asking for it and timestamp of last read
  2. when the client needs a ticker, call a server function that adds the ticker and client id to that table
  3. a background task scheduled to run every x seconds or minutes or hours, gets the list of unique tickers from the table (ie removing the duplicates in case two clients are waiting for the same ticker), gets the prices and updates the table
  4. the tick event of a timer on the form calls a server function every few seconds to get the values from the table. When the server function returns the value to the tick event, it also updates the timestamp
  5. a second scheduled task runs every hour and deletes all the rows that have the timestamp older than a minute or an hour or whatever suggests that the client is not reading that value any longer

On step 2, if the interval for the scheduled task is longer than a few seconds, it should also launch the background task, so the value is quickly available

4 Likes