M031097
asked on
Thread-problem
Hello,
"Houston, we have a problem"
Well, I do anyway. I'm trying to learn how to use threads.
And well, I must be missing something (probably a brain)
Can you please explain why this doesn't work and how to
fix it?
The problem is that the dialog isn't shown.
See code below.
UINT myThread(LPVOID param)
{
MyDialog dlg;
dlg.DoModal();
}
void MyClass::startIt()
{
CWinThread* thread = AfxBeginThread(myThread, 0)
thisTakesTime();
_endthread(thread->m_nThre adID);
}
All I want to do is to show a DialogBox with a progress-
control, while I do an operation that takes alot of time.
And, of course, when this operation is finished kill the
thread and DialogBox.
I am confused, I thought this was the way.
If I change myThread-func to only display a MessageBox
it works fine. The MessgeBox is displayed.
Regards,
-M-
"Houston, we have a problem"
Well, I do anyway. I'm trying to learn how to use threads.
And well, I must be missing something (probably a brain)
Can you please explain why this doesn't work and how to
fix it?
The problem is that the dialog isn't shown.
See code below.
UINT myThread(LPVOID param)
{
MyDialog dlg;
dlg.DoModal();
}
void MyClass::startIt()
{
CWinThread* thread = AfxBeginThread(myThread, 0)
thisTakesTime();
_endthread(thread->m_nThre
}
All I want to do is to show a DialogBox with a progress-
control, while I do an operation that takes alot of time.
And, of course, when this operation is finished kill the
thread and DialogBox.
I am confused, I thought this was the way.
If I change myThread-func to only display a MessageBox
it works fine. The MessgeBox is displayed.
Regards,
-M-
Your thread needs to have its own message loop, and since you need to display a progress bar, it should be modeless dialog box. Besides, try to remove the endthread() call, instead, let the thread inform the main thread that it is terminated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, I mean you're creating a worker-thread.