Link to home
Start Free TrialLog in
Avatar of Galilea
Galilea

asked on

How to update display and do the computation at the same time.

I have to do some computation while printing out different steps of it. In the same application I have a real time clock which uses ONTIMER event however, it freezes once the computation starts so cannot use it to update edit control. How can I update the edit control with the text saying what it is doing at the same time as doing the computation?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Threads create additional overhead and gotchas, though...
Avatar of Galilea
Galilea

ASKER

Jaime, just tried it,
Do I have to put the computation on the thread or the updating. At the moment I have the following:

::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ComputingFunction, 0, 0, &IdThread);

CPDRecorder_alphaApp::m_LogTrace.WriteLine("Finished Acquisition");
UpdateData();
ss.Format("%s\tFinish ACQ\r\n", COleDateTime::GetCurrentTime().Format("%d/%m/%y, %H:%M:%S "));
m_strStatus += ss;  
UpdateData(FALSE);

// Create filename string
sTime.Format("%s", COleDateTime::GetCurrentTime().Format("%H%M%S"));
for (numChan = 1; numChan<5; numChan++)
{
      ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SavingFunction, 0, 0, &IdThread1);
      UpdateData();
      ss.Format("%s\tCH%i: Timestamp:%i Saved\r\n", COleDateTime::GetCurrentTime().Format("%d/%m/%y, %H:%M:%S "),
            numChan, iFrameCount);
      m_strStatus += ss;  
      UpdateData(FALSE);
      fclose(outfile);
      UpdateData();
      ss.Format("%s\tCH%i: Saved\r\n", COleDateTime::GetCurrentTime().Format("%d/%m/%y, %H:%M:%S "),
            numChan);
      m_strStatus += ss;  
      UpdateData(FALSE);
      CPDRecorder_alphaApp::m_LogTrace.WriteLine("CH%i Saved", numChan);
}

Now, this probably sounds odd (it sounds odd to me) but if I do not put the thread ComputingFunction, and just put in in serial, the UpdateData does not occur, it just jumped onto the acquisition without updating. Now that I have put the thread, it jumps to the acquisition without having finished computing... does this makes sense. If so, how can I fix it?
Avatar of Galilea

ASKER

... by the way, it's not all the code, just the extracts which I thought were of interest.
Avatar of Galilea

ASKER

Should I use jkr's technique, however, not too sure how I'm supposed to use it, sorry jkr
It's a bit confussing, but I guess you want to show some progress information of your calculus somewhere.
You can do it from your calculation thread passsing some messages to your dialog, or you can put progress information in some global variable or object, and update dialog "asynchronously" with a timer in your dialog that reads this global information.
>>however, not too sure how I'm supposed to use it

If this is your computing loop, use

for (numChan = 1; numChan<5; numChan++)
{
    DoEvents ();

    // do calculations
}
Check out MFC sample MTRECALC.