Click here to Skip to main content
15,908,906 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: [OT] Re: object life cycle question Pin
tyr200025-Feb-09 13:01
tyr200025-Feb-09 13:01 
GeneralRe: object life cycle question Pin
tyr200025-Feb-09 13:32
tyr200025-Feb-09 13:32 
GeneralRe: object life cycle question Pin
Maximilien25-Feb-09 3:46
Maximilien25-Feb-09 3:46 
GeneralRe: object life cycle question Pin
David Crow25-Feb-09 6:18
David Crow25-Feb-09 6:18 
GeneralRe: object life cycle question Pin
tyr200025-Feb-09 13:14
tyr200025-Feb-09 13:14 
AnswerRe: object life cycle question Pin
Stuart Dootson25-Feb-09 8:55
professionalStuart Dootson25-Feb-09 8:55 
GeneralRe: object life cycle question Pin
tyr200025-Feb-09 13:12
tyr200025-Feb-09 13:12 
GeneralRe: object life cycle question Pin
Stuart Dootson25-Feb-09 15:14
professionalStuart Dootson25-Feb-09 15:14 
No, there's more to it than that. Typically, a program using an auxiliary thread will probably have one of two patterns:

  1. A thread that does one thing then exits its thread function


    The auxiliary thread exits of its own volition. The main thread can then check that the thread has exitted using the GetExitCodeThread[^] function (the functions shows a thread exit code of STILL_ACTIVE if the thread hasn't terminated), or can wait for the thread to exit using the WaitForSingleObject[^] function, using the thread handle as the handle to wait for (a thread's handle is set when the thread exits).
  2. A thread that does many things in a loop


    In this case, you need some way of telling the thread that it's time to exit. In general, you could use a boolean flag that the thread can check each time round the loop (use InterlockedExchange[^] to set the flag from the main thread) or you could use an event[^] - the main thread would set the event to indicate that the other thread should exit, the other thread use WaitForSingleObject to see if the event's been set). In either case, the main thread would notify the other thread that it's time to exit, then wait for the thread to exit using WaitForSingleObject.


Use the appropriate pattern (I suspect it's the second from what you've said) when the thing that created the thread (your cmainwnd?) is destroyed.

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

QuestionHow to enabling CMainFrame to have the cursor when the application starts Pin
susanne125-Feb-09 2:48
susanne125-Feb-09 2:48 
AnswerRe: How to enabling CMainFrame to have the cursor when the application starts Pin
Sarath C25-Feb-09 3:04
Sarath C25-Feb-09 3:04 
GeneralRe: How to enabling CMainFrame to have the cursor when the application starts Pin
susanne125-Feb-09 3:22
susanne125-Feb-09 3:22 
GeneralRe: How to enabling CMainFrame to have the cursor when the application starts Pin
susanne125-Feb-09 5:10
susanne125-Feb-09 5:10 
GeneralRe: How to enabling CMainFrame to have the cursor when the application starts Pin
Sarath C25-Feb-09 5:59
Sarath C25-Feb-09 5:59 
GeneralRe: How to enabling CMainFrame to have the cursor when the application starts Pin
susanne125-Feb-09 6:11
susanne125-Feb-09 6:11 
QuestionLinker Extern Erros from MFC objects Pin
ForNow25-Feb-09 2:38
ForNow25-Feb-09 2:38 
AnswerRe: Linker Extern Erros from MFC objects Pin
Sarath C25-Feb-09 2:48
Sarath C25-Feb-09 2:48 
GeneralRe: Linker Extern Erros from MFC objects Pin
ForNow25-Feb-09 7:04
ForNow25-Feb-09 7:04 
QuestionMBCS with Unicode Pin
Member 475657425-Feb-09 2:26
Member 475657425-Feb-09 2:26 
AnswerRe: MBCS with Unicode Pin
«_Superman_»25-Feb-09 2:28
professional«_Superman_»25-Feb-09 2:28 
GeneralRe: MBCS with Unicode Pin
Member 475657425-Feb-09 2:36
Member 475657425-Feb-09 2:36 
GeneralRe: MBCS with Unicode Pin
«_Superman_»25-Feb-09 2:41
professional«_Superman_»25-Feb-09 2:41 
AnswerRe: MBCS with Unicode Pin
Sarath C25-Feb-09 3:01
Sarath C25-Feb-09 3:01 
QuestionBuffer to HDC handle Pin
Elsie25-Feb-09 2:24
Elsie25-Feb-09 2:24 
QuestionRe: Buffer to HDC handle Pin
CPallini25-Feb-09 2:52
mveCPallini25-Feb-09 2:52 
AnswerRe: Buffer to HDC handle Pin
Elsie25-Feb-09 2:59
Elsie25-Feb-09 2:59 

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.