Re: Waiting for Dialog to update in a Nnew Thread



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]

.



Relevant Pages

  • Re: Safety pilot - logging cross-country
    ... So your "Can the safety pilot..." ... : manipulating the controls. ... Consider a MEL-rated pilot acting as PIC with his buddy with SEL-rating flying ... The acting PIC cannot because he's not physically manipulating the ...
    (rec.aviation.ifr)
  • Re: Let a friend fly the plane. Legal?
    ... :> the controls, but then neither may log that time. ... and logging PIC time in the FARs, that there was no way the acting PIC can log PIC ... time if a non-pilot was manipulating the controls. ... "Also, a pilot, rated in category and class could, as ...
    (rec.aviation.ifr)
  • Re: ADIZ Violation Explained in AOPA Magazine
    ... > The passenger was manipulating the controls, ... > places any navigational responsibility on him--especially since his ... > cross-country training hadn't even begun yet. ...
    (rec.aviation.piloting)
  • Re: Simulation isnt flying
    ... It takes more than manipulating the controls to be ... Yet another reason to use simulation instead. ...
    (rec.aviation.student)