Waiting for Dialog to update in a Nnew Thread
- From: "Alan Hadley" <alan_hadley@xxxxxxxxxxxxxxxx>
- Date: Sat, 05 Nov 2005 10:18:07 GMT
I have a main thread that controls all of the UI and calculations. I want
another thread to maintain a progress/log, and also to show a Cancel button
to interrupt long calculations in the main thread, the main window is hidden
during these calculations but the progress box is vizible.
I want a list control in the progress box to say what stage the calculations
have reached.
I have got the thing working by running the processing functions in new
threads but the code is messy, and hard to maintain. So I want to do
something like this:-
// this is a function from my dialog class
void CProgress::AddString(char *s)
{
m_list.AddString(s);
m_list.SetTopIndex(m_list.GetCount()-1);
UpdateWindow();
}
// This function is in the same class as the instance of the dialog above,
the thread class
//{{AFX_MSG_MAP(CProgressThread)
ON_THREAD_MESSAGE(WM_PROGRESS_ADD,Add)
void CProgressThread::Add(WPARAM w,LPARAM l)
{
HANDLE event;
event=OpenEvent(EVENT_ALL_ACCESS,true,"AddEvent");
progress.AddString((char*)l); // ***
SetEvent(event);
CloseHandle(event);
}
// This functuion is in the main processing class, I want it to wait until
the text appears in the dialog
char* t[128];
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
.
- Follow-Ups:
- Re: Waiting for Dialog to update in a Nnew Thread
- From: Alan Hadley
- Re: Waiting for Dialog to update in a Nnew Thread
- From: Joseph M . Newcomer
- Re: Waiting for Dialog to update in a Nnew Thread
- From: Scott McPhillips [MVP]
- Re: Waiting for Dialog to update in a Nnew Thread
- From: David Lowndes
- Re: Waiting for Dialog to update in a Nnew Thread
- Prev by Date: RE: Why does CSocket->Create() hang forever?
- Next by Date: Re: Waiting for Dialog to update in a Nnew Thread
- Previous by thread: Re: what's difference between DS_CONTROL & WS_EX_CONTROLPARENT
- Next by thread: Re: Waiting for Dialog to update in a Nnew Thread
- Index(es):