Solved

Thread-problem

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows 10 how make picture as desktop background 2 66
Shell script to login to remote m/c and execute commands 10 78
move a line in eclipse 3 109
Capture logon name 13 100
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 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