I'm trying to experiment a little in using AfxBeginThread(). I'm having some problems though and I think I know what it is, but I would like some input from any veterans out there. I've got a program that does some things and I want a little Dlg resource box to pop (worker/UI thread) up for a bit until the main program gets done with what it's doing. Here is my problem:
I think I've got the skeleton down. I've defined the following:
CWinThread* pThread = AfxBeginThread(ComputeThreadProc, GetSafeHwnd(), THREAD_PRIORITY_NORMAL);
Then my actual ComputeThreadProc() looks like this:
UINT ComputeThreadProc(LPVOID pParam)
{
while (PostUpdateDone == 0)
{
CUpdate *Update = new CUpdate;
Update->DoModal();
PostUpdateDone = 1;
}
if (PostUpdateDone == 2)
Update->DestroyWindow();
return 0
}
PostUpdateDone is defined as an 'int volatile; basically a flag so the thread will know when to kill my Update dlg box.
CUpdate is a simple resource dlg box that says, "Please wait"
So, here is my problem. I comment out everything in my ComputeThreadProc() and everything works okay....It enters the thread and the thread exits properly when it is supposed to...at least that what Spy++ and the VC++ Debug window appears to show. My code errors out on the line Update->DoModal(). I'm thinking that I can't just use a worker thread here....it has to be more of a UI thread...and I'm guessing that if I can overload my
pThread->InitInstance() function to pop my Update dlg box, everything will work out....maybe. Does anyone have any comments or info about this? There is something I'm overlooking here and I just don't know what it is. The actual error I'm getting is an assertion error, but then a 1/2 second later a 'User breakpoint called from code at 0x.....' appears and I can't click on retry to jump into the code to see where it's screwing up. BTW, using VC++ 6.0. Thanks in advance for any help or direction!
Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
I think I've got the skeleton down. I've defined the following:
CWinThread* pThread = AfxBeginThread(ComputeThreadProc, GetSafeHwnd(), THREAD_PRIORITY_NORMAL);
Then my actual ComputeThreadProc() looks like this:
UINT ComputeThreadProc(LPVOID pParam)
{
while (PostUpdateDone == 0)
{
CUpdate *Update = new CUpdate;
Update->DoModal();
PostUpdateDone = 1;
}
if (PostUpdateDone == 2)
Update->DestroyWindow();
return 0
}
PostUpdateDone is defined as an 'int volatile; basically a flag so the thread will know when to kill my Update dlg box.
CUpdate is a simple resource dlg box that says, "Please wait"
So, here is my problem. I comment out everything in my ComputeThreadProc() and everything works okay....It enters the thread and the thread exits properly when it is supposed to...at least that what Spy++ and the VC++ Debug window appears to show. My code errors out on the line Update->DoModal(). I'm thinking that I can't just use a worker thread here....it has to be more of a UI thread...and I'm guessing that if I can overload my
pThread->InitInstance() function to pop my Update dlg box, everything will work out....maybe. Does anyone have any comments or info about this? There is something I'm overlooking here and I just don't know what it is. The actual error I'm getting is an assertion error, but then a 1/2 second later a 'User breakpoint called from code at 0x.....' appears and I can't click on retry to jump into the code to see where it's screwing up. BTW, using VC++ 6.0. Thanks in advance for any help or direction!
Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com