Solved

Thread-problem

Posted on 1997-08-22
3
381 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, I mean you're creating a worker-thread.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
if loop in java 3 114
lucky13 challenge 11 111
only14 challenge 19 63
Making an alias 7 51
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

13 Experts available now in Live!

Get 1:1 Help Now