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.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Threads create additional overhead and gotchas, though...
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)Co mputingFun ction, 0, 0, &IdThread);
CPDRecorder_alphaApp::m_Lo gTrace.Wri teLine("Fi nished Acquisition");
UpdateData();
ss.Format("%s\tFinish ACQ\r\n", COleDateTime::GetCurrentTi me().Forma t("%d/%m/% y, %H:%M:%S "));
m_strStatus += ss;
UpdateData(FALSE);
// Create filename string
sTime.Format("%s", COleDateTime::GetCurrentTi me().Forma t("%H%M%S" ));
for (numChan = 1; numChan<5; numChan++)
{
::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Sa vingFuncti on, 0, 0, &IdThread1);
UpdateData();
ss.Format("%s\tCH%i: Timestamp:%i Saved\r\n", COleDateTime::GetCurrentTi me().Forma t("%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::GetCurrentTi me().Forma t("%d/%m/% y, %H:%M:%S "),
numChan);
m_strStatus += ss;
UpdateData(FALSE);
CPDRecorder_alphaApp::m_Lo gTrace.Wri teLine("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?
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)Co
CPDRecorder_alphaApp::m_Lo
UpdateData();
ss.Format("%s\tFinish ACQ\r\n", COleDateTime::GetCurrentTi
m_strStatus += ss;
UpdateData(FALSE);
// Create filename string
sTime.Format("%s", COleDateTime::GetCurrentTi
for (numChan = 1; numChan<5; numChan++)
{
::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Sa
UpdateData();
ss.Format("%s\tCH%i: Timestamp:%i Saved\r\n", COleDateTime::GetCurrentTi
numChan, iFrameCount);
m_strStatus += ss;
UpdateData(FALSE);
fclose(outfile);
UpdateData();
ss.Format("%s\tCH%i: Saved\r\n", COleDateTime::GetCurrentTi
numChan);
m_strStatus += ss;
UpdateData(FALSE);
CPDRecorder_alphaApp::m_Lo
}
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?
ASKER
... by the way, it's not all the code, just the extracts which I thought were of interest.
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.
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
}
If this is your computing loop, use
for (numChan = 1; numChan<5; numChan++)
{
DoEvents ();
// do calculations
}
Check out MFC sample MTRECALC.