I am writing something in WPF, and I need to perform some calculations in the background (on other threads) so it doesn't impact the performance of the UI.
I've got a Window class which is where I'm doing some UI logic, and this is where I call new Calculations()
instance. In Window I've also got a List<CalculationFormulas>
(each CalculationFormula is a calculation that needs to be run). Sometimes CalculationFormula's will need to be run concurrently as well. I pass the list to Calculations when I construct the Calculations object as mentioned above.
In the Calculations constructor I kick off a worker thread asynchronously to start the first CalculationFormula in the list, then at the appropriate point that worker thread kicks off the next CalculationFormula in the list asynchronously, and so on until the list is empty (as the CalculationFormula is removed from this list when calculations are finished).
MY QUESTIONS:
1) How can I send a list of the currently running calculations back to Window? Even though they are all running in different threads, is it possible for me to have a property in calculations, say List<CalculationFormula>
RunningCalculations that I update from each thread... and then just call Calculations.RunningCalculations
from Window?
2) If the List<CalculationFormula>
that I passed in to Calculations initially changes, how can I pass the new list through to Calculations such that all of the currently running threads will know it has changed. Would I need to trigger an event somehow?
3) Every time a calculation finishes, how can I ensure Window knows about this (so it can be reflected in the UI)? How would I set up an event such that each thread would trigger the event just before it closes (ie. when the calculation has finished)?
Thank you