Click here to Skip to main content
15,912,837 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCListCtrl Pin
AnithaSubramani18-Aug-08 21:36
AnithaSubramani18-Aug-08 21:36 
AnswerRe: CListCtrl Pin
Jijo.Raj18-Aug-08 21:48
Jijo.Raj18-Aug-08 21:48 
AnswerRe: CListCtrl Pin
Hamid_RT19-Aug-08 3:53
Hamid_RT19-Aug-08 3:53 
QuestionI started the thread and want to wait until the thread completes [modified] Pin
ptr_Electron18-Aug-08 20:28
ptr_Electron18-Aug-08 20:28 
AnswerRe: I started the thread and want to wait until the thread completes [modified] Pin
SandipG 18-Aug-08 20:40
SandipG 18-Aug-08 20:40 
GeneralRe: I started the thread and want to wait until the thread completes Pin
ptr_Electron18-Aug-08 20:42
ptr_Electron18-Aug-08 20:42 
GeneralRe: I started the thread and want to wait until the thread completes [modified] Pin
SandipG 18-Aug-08 20:45
SandipG 18-Aug-08 20:45 
AnswerRe: I started the thread and want to wait until the thread completes Pin
Stephen Hewitt18-Aug-08 21:07
Stephen Hewitt18-Aug-08 21:07 
Try something like this:

// Create the worker thread. It starts suspended so we can duplicate
// the thread handle through "pThread" before the thread exits and MFC deletes
// it. This scenario seems to be a race condition in the MFC "AfxBeginThread"
// functions you need to watch out for - although the chances of it
// actually occurring are slim.
CWinThread *pThread = AfxBeginThread(&StartUpdateUIThread, _param, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
ASSERT(pThread);
// NOTE:
//  Don't delete "pThread" - It will be deleted automatically
// when the thread exits.
 
// Duplicate the thread handle so we can wait on it safe in the knowledge
// that MFC won't close it behind our back when the thread exits.
HANDLE hThread;
VERIFY(DuplicateHandle(GetCurrentProcess(), *pThread, GetCurrentProcess(), &hThread, 0, FALSE, DUPLICATE_SAME_ACCESS));
 
// Start up the worker thread now we've got a handle to it to wait on.
pThread->ResumeThread();
 
// Wait for it to die.
WaitForSingleObject(hThread, INFINITE);
 
// Don't forget to close the HANDLE when you're done with it!
CloseHandle(hThread);


It's probably a good idea to wrap all this mess in a helper function.

Steve

AnswerRe: I started the thread and want to wait until the thread completes Pin
Roger Stoltz18-Aug-08 22:33
Roger Stoltz18-Aug-08 22:33 
QuestionRe: I started the thread and want to wait until the thread completes Pin
Mark Salsbery19-Aug-08 8:01
Mark Salsbery19-Aug-08 8:01 
QuestionUsing DotNET API in MFC application Pin
ComplexLifeForm18-Aug-08 20:04
ComplexLifeForm18-Aug-08 20:04 
AnswerRe: Using DotNET API in MFC application Pin
Rajesh R Subramanian18-Aug-08 20:09
professionalRajesh R Subramanian18-Aug-08 20:09 
AnswerRe: Using DotNET API in MFC application Pin
Hamid_RT18-Aug-08 20:19
Hamid_RT18-Aug-08 20:19 
QuestionRemote Procedure Call. Pin
T.RATHA KRISHNAN18-Aug-08 19:48
T.RATHA KRISHNAN18-Aug-08 19:48 
AnswerRe: Remote Procedure Call. Pin
User 21559718-Aug-08 19:55
User 21559718-Aug-08 19:55 
QuestionRe: Remote Procedure Call. Pin
T.RATHA KRISHNAN18-Aug-08 20:01
T.RATHA KRISHNAN18-Aug-08 20:01 
AnswerRe: Remote Procedure Call. Pin
Rajesh R Subramanian18-Aug-08 20:05
professionalRajesh R Subramanian18-Aug-08 20:05 
AnswerRe: Remote Procedure Call. Pin
toxcct19-Aug-08 23:46
toxcct19-Aug-08 23:46 
AnswerRe: Remote Procedure Call. Pin
_AnsHUMAN_ 18-Aug-08 20:04
_AnsHUMAN_ 18-Aug-08 20:04 
AnswerRe: Remote Procedure Call. Pin
Rajesh R Subramanian18-Aug-08 20:04
professionalRajesh R Subramanian18-Aug-08 20:04 
AnswerRe: Remote Procedure Call. Pin
David Crow19-Aug-08 3:36
David Crow19-Aug-08 3:36 
Questionerror C2011 Pin
vcprog18-Aug-08 19:08
vcprog18-Aug-08 19:08 
AnswerRe: error C2011 Pin
Jijo.Raj18-Aug-08 19:44
Jijo.Raj18-Aug-08 19:44 
GeneralRe: error C2011 Pin
vcprog18-Aug-08 20:06
vcprog18-Aug-08 20:06 
GeneralRe: error C2011 Pin
Jijo.Raj18-Aug-08 21:42
Jijo.Raj18-Aug-08 21:42 

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.