Solved

Thread-problem

Posted on 1997-08-22
3
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 172
wait notify demo infinite loop 3 150
modThree challenge 4 155
scoreUp challenge 14 74
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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