Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AfxBeginThread help

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
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
 
Fixed my problem for the most part, seems as though I needed to make a modeless dlg box; however, the process seems to wait till it's done BEFORE it does the
sub-thread. I can't figgure out why my "please wait" dialog box isn't the first to come up. On my OnCickButtonXXX() function, I call my AfxBeginThread() function on the first line. That should start that thread and go directly into the ComputeThreadProc(); I've stepped through it and it seems like it is going through the ComputeThreadProc(), but my modeless dlg box isn't coming up...it waits till the main process is done. I even call SetFocus() and SetForegroundWindow(). Any ideas? Thanks in advance!

Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top