Solved

Thread-problem

Posted on 1997-08-22
3
384 Views
Last Modified: 2013-11-20
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_nThreadID);
}

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-
0
Comment
Question by:M031097
  • 2
3 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1304545
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.
0
 
LVL 3

Accepted Solution

by:
byang earned 80 total points
ID: 1304546
You're creating a user-thread, there's another form  of AfxBeginThread() which creates a UI-thread.

You should not call _endthread to kill the thread. Instead the dialog box should close itself after progress reaches 100%, then you just exit from myThread(), or use AfxEndThread() within myThread().
0
 
LVL 3

Expert Comment

by:byang
ID: 1304547
Sorry, I mean you're creating a worker-thread.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 104
Doc'in system (example?) BA 7 86
haveThree challenge 22 112
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 187
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short film showing how OnPage and Connectwise integration works.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now