Am 29.01.2012 02:49, schrieb Bruce Varley:
> Hi, Just after a bit of advice on structuring a program (not homework).
> This is an old process simulator that I'm porting from DOS to Win32 (MFC).
> The core consists of a big loop that solves DEs inter alia, and outputs to
> the screen as it goes. That works better than doing all the computation
> first, then displaying it all at the end, because on a long run (up to a
> minute if the problem is big) you can see how things are going and stop if
> you want.
In other words, even while computing stuff the program remains
"responsive", both in the sense of input and output.
> The old version was just a loop in main(), and I can replicate
> this on the new platform, presumably the loop would be in the application
> initialisation. ie the 'initialisation' would be the whole thing.
>
> That seems a bit crude.
This will cause the startup to not happen until all computations are
complete. This has two consequences:
1. Your application will start with a delay of a minute. Experience
shows that after ten seconds without response, users will just try to
start the application again.
2. You can't input parameters via the GUI, because at the time you get a
UI, all computations are already done.
I don't think that doing things in the initialization is the way to go.
The way I imagine this is that the UI starts up and allows the user to
input parameters and then to start the simulation. The simulation is
running parallel to the UI, so new results are regularly displayed. This
can either be done with a timer function (see SetTimer/KillTimer) or a
separate worker thread. If you're not familiar with multithreading, go
for the timer, although multithreading would give better results and
allow making better use of multiple CPUs.
Good luck!
Uli