I have a series of calculations that need to be processed - the calculations and the order of their launch are determined by the user in the user interface.
If they just ran one after another, that would not be too difficult. However, some calculations must be processed simultaneously, and all calculations must be able to individually pause at any time. I also need to be able to reorder orders or add new calculations for processing at any time. So everything I do should be flexible enough to handle this.
In the user interface, imagine a list (queue, if you want) of usercontrols - each user control displays a calculation name and a pause button. And I can add calculations to this list at any time during processing.
What is the best way to do this?
Do I have to run each calculation in my thread? If so, how do I keep a list of running processes? How to pass a queue to the processor of calculations? How can I guarantee that every time the queue changes (new order or new calculation), the calculation processor will be informed about this?
My initial thoughts were as follows:
CalcProcessor classCalcCalculation class
There are 2 Lists of CalcCalculations . One of them is a โqueueโ, as shown in the user interface (perhaps a pointer to it or some other way to ensure its updating in real time), and the other is a list of current calculations.
Somehow I need to run CalcCalculation in my thread to handle the calculation and be able to handle any pause events. Therefore, I need to somehow pass the information about the Pause button pressed in the user interface to the CalcProcessor object, and then to the correct CalcCalculation .
Edit in response to David Hope:
Thanks for your reply.
Yes, there are n calculations, but this can change at any time due to the ability to add additional calculations for processing in the user interface.
In any case, they do not need to exchange data. The application will indicate how many of them should be started at the same time (i.e. 10 at any time, for example, the first 10 in the queue, and when 1 ends, the next calculation in the queue will start processing).
The calculation will include obtaining data from some data source โ it can be a database or a file, as well as analyzing and performing some calculations on this data. When I say that the calculation should be suspended, I do not mean to suspend the flow ... I mean (for example, since I have not written this part of the application yet) if it reads line by line from the database and do whatever then live calculations, stopping at the end of processing the current line ... and continuing when the pause button is not decoupled in the user interface - which can be done with something as primitive as the while (notPaused) loop, which I can get Pause information from the user interface to the stream.
source share