Click here to Skip to main content
15,917,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionpointer sized data of poi command Pin
George_George7-Oct-08 20:57
George_George7-Oct-08 20:57 
QuestionHow to download only images from the webpage Pin
Sandeep Saini SRE7-Oct-08 20:55
Sandeep Saini SRE7-Oct-08 20:55 
AnswerRe: How to download only images from the webpage Pin
Hamid_RT7-Oct-08 21:04
Hamid_RT7-Oct-08 21:04 
QuestionConvert Fortran Code Pin
Trupti Mehta7-Oct-08 20:43
Trupti Mehta7-Oct-08 20:43 
AnswerRe: Convert Fortran Code Pin
Saurabh.Garg7-Oct-08 21:12
Saurabh.Garg7-Oct-08 21:12 
QuestionRe: Convert Fortran Code Pin
CPallini7-Oct-08 23:03
mveCPallini7-Oct-08 23:03 
QuestionYielding Messages.... Pin
Peter Weyzen7-Oct-08 19:23
Peter Weyzen7-Oct-08 19:23 
AnswerRe: Yielding Messages.... Pin
Roger Stoltz7-Oct-08 22:24
Roger Stoltz7-Oct-08 22:24 
Peter Weyzen wrote:
I've always wondered if it might be a hack...


Mmm, it is a hack. Wink | ;)

What you normally do when waiting for a thread to finish is to wait on the thread handle with a call to any of the wait functions such as ::WaitForSingleObject(). There you also have the possibility to provide a timeout value.

To be able to do that you first create your thread suspended and then set the CWinThread::m_bAutoDelete member to FALSE before unleashing the thread with a call to CWinThread::ResumeThread(). This prevents the CWinThread object from doing a "delete this" when the thread finishes, otherwise the thread handle will become invalid since the handle will be closed in the CWinThread destructor call chain. Of course this means that you have to destroy the CWinThread object yourself when the thread has finished.

Since it's a UI-thread you post a WM_QUIT message to the thread and then wait on the thread handle. When the thread finishes, the wait function will return and then you can delete the CWinThread object.

This excellent article[^] is absolutely worth reading when it comes to multithreading. Even though the article refers to worker threads explicitly, the mind set is very much the same for UI-threads when shutting down apart from the WM_QUIT message.


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


GeneralRe: Yielding Messages.... Pin
Peter Weyzen7-Oct-08 22:33
Peter Weyzen7-Oct-08 22:33 
GeneralRe: Yielding Messages.... Pin
Mark Salsbery8-Oct-08 5:55
Mark Salsbery8-Oct-08 5:55 
QuestionThread question Pin
monsieur_jj7-Oct-08 19:19
monsieur_jj7-Oct-08 19:19 
AnswerRe: Thread question Pin
Michael Dunn7-Oct-08 19:37
sitebuilderMichael Dunn7-Oct-08 19:37 
GeneralRe: Thread question Pin
monsieur_jj7-Oct-08 20:05
monsieur_jj7-Oct-08 20:05 
GeneralRe: Thread question Pin
Cedric Moonen7-Oct-08 20:12
Cedric Moonen7-Oct-08 20:12 
GeneralRe: Thread question Pin
monsieur_jj7-Oct-08 20:23
monsieur_jj7-Oct-08 20:23 
GeneralRe: Thread question Pin
Cedric Moonen7-Oct-08 20:29
Cedric Moonen7-Oct-08 20:29 
QuestionFunction calling in header file Pin
Davitor7-Oct-08 19:05
Davitor7-Oct-08 19:05 
AnswerRe: Function calling in header file Pin
ThatsAlok7-Oct-08 19:18
ThatsAlok7-Oct-08 19:18 
GeneralRe: Function calling in header file Pin
Davitor7-Oct-08 19:26
Davitor7-Oct-08 19:26 
GeneralRe: Function calling in header file Pin
ThatsAlok7-Oct-08 20:00
ThatsAlok7-Oct-08 20:00 
AnswerRe: Function calling in header file Pin
Cedric Moonen7-Oct-08 20:15
Cedric Moonen7-Oct-08 20:15 
AnswerRe: Function calling in header file Pin
CPallini7-Oct-08 23:06
mveCPallini7-Oct-08 23:06 
AnswerRe: Function calling in header file Pin
Bram van Kampen8-Oct-08 9:03
Bram van Kampen8-Oct-08 9:03 
QuestionPrinter HW Serial Number Pin
Bram van Kampen7-Oct-08 15:04
Bram van Kampen7-Oct-08 15:04 
AnswerRe: Printer HW Serial Number Pin
Garth J Lancaster7-Oct-08 16:14
professionalGarth J Lancaster7-Oct-08 16:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.