Solved

Thread-problem

Posted on 1997-08-22
3
387 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 91
Installing Microsoft R server on REDHAT or SUSE Linux 4 138
sum28 challenge 31 112
Thin secure Windows 10 5 98
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…
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.

821 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