Maybe my approach is wrong, feel free to correct me.
I have the following method on my service:
public void PublishPriceChange()
{
for (int i = 0; i < 200; i++)
{
Task.Run(() =>
{
int j = i;
lock (_locker)
{
TransformPrices(_quotes);
PriceChangeEventArgs e = new PriceChangeEventArgs(_quotes);
PriceChanged(this, e);
}
});
}
}
_quotes
contains the opening prices of the day and TransformPrices()
simply changes these prices slightly upon each call. This simulates the changes during a day. Hence these tasks have to be run in a sequential way.
However having them running like this on a thread pool means each task is running in parallel and no longer in a sequence.
Obviously I could just run them without multi threading to get the required effect. However since the calculation takes some time, it would be good to keep the service responsive while its doing these tasks in the background.
Maybe I could use Continuations
(awaiter) but not sure how to chain this all way through.
Any advice?