Re: Pausing and continuing MFC Thread
"Lucress Carol" <firstname.lastname@example.org> ha scritto nel messaggio
I'm having troubles with pausing and continuing MFC Thread.
this question would be better suited for the MFC newsgroup
homepage: http://www.flounder.com/workerthreads.htm and frankly
speaking I still don't understand how : CEvent (SetEven, CreateEvent),
You can find Joe (the author of the article) on the MFC newsgroup.
Here is for example what should
occur when one the Start Button clicks:
int i, count;
while (count< 170)
The problem with this code executed in the main GUI thread is that you are
blocking the main GUI thread.
You should put this code in a worker thread (which can be launched using
AfxBeginThread), so the main GUI thread can be free to process the messages
sent by Windows (or by other worker threads).
In the OnBnStart handle you should start the worker thread, and in the
OnBnStop button you should stop it.
But the lengthy calculations and processing should be all done inside the
*worker* thread (not in the GUI thread).
When the GUI thread executed a "chunk" of processing, you can't call
m_progressBarCtrl.SetPos() from the worker thread directly; instead, your
worker thread should post a message to the main GUI thread (a custom
message) to signal the amount of processing completed. A message has WPARAM
and LPARAM, so you can put this amount-of-processing-completed (e.g. a
DWORD) in one of the message parameters.
In the main GUI thread, you can have a handle for this custom message, and
in this handle you can safely call m_ProgressBarCtrl.SetPos(). This handle
(executed in main GUI thread) extracts the amount-of-processing-completed
from the custom message WPARAM or LPARAM, and calls
m_ProgressBarCtrl.SetPos() to update progress bar.