Re: Waiting for Dialog to update in a Nnew Thread
- From: "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
- Date: Sat, 05 Nov 2005 12:09:07 -0600
Alan Hadley wrote:
void CCombineDoc::AddString(CString s) { if(s.GetLength()>127) s=s.Left(127); strcpy(t,s); HANDLE event; event=CreateEvent(0,true,false,"AddEvent"); progress->PostThreadMessage(WM_PROGRESS_ADD,0,(long)t); WaitForSingleObject(event,INFINITE); CloseHandle(event); }
But it locks up. If I comment out the line marked // *** the Wait works properly, so the problem is something to do with manipulating the dialog controls.
Any suggestions?
Alan
I suspect that you created the progress dialog in the main thread, but are attempting to update it from the secondary thread. This would cause the lockup. You cannot update a control created in the main thread if the main thread is suspended in a WaitFor...
You threw out the best solution because, you said, "the code is messy." Maybe so. But interthread communication is inherently restricted to doing what is thread-safe. You can't use multithreading without accounting for its inherent restrictions.
-- Scott McPhillips [VC++ MVP]
.
- References:
- Waiting for Dialog to update in a Nnew Thread
- From: Alan Hadley
- Waiting for Dialog to update in a Nnew Thread
- Prev by Date: Re: Get Parent Dialog into Child window
- Next by Date: Re: Get Parent Dialog into Child window
- Previous by thread: Re: Waiting for Dialog to update in a Nnew Thread
- Next by thread: Re: Waiting for Dialog to update in a Nnew Thread
- Index(es):
Relevant Pages
|