Re: Waiting to thread exit
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sun, 09 Sep 2007 11:56:14 -0400
When your thread terminates, which it does by posting a message to itself to quit, what it
does just before that is post a message to the main thread indicating that it has
finished. The main thread can handle the backups and launching.
Alternatively, at the point where you know the thread is about to finish, you would make
the backup in the thread itself, and proceed only if this succeeded.
Essentially, you *don't* need to know when the thread finishes, you only need to know it
has done its job. Doing al this from CMyApp::OnInitInstance is also probably a design
error. All that InitInstance should be doing is bringing up your app. THEN you launch
the thread, and if it fails, you take the app down. You are still thinking in a
completely synchronous model. There is no need to use a thread at all for what you are
doing; if you want a thread, the purpose is to get concurrency, and you are not in need of
concurrency if you are doing this in InitInstance! Let the app come up, display its
progress bar, do its copy, etc., and then continue to run, or come up with most menu items
disabled. Putting anything like this in InitInstance is just the wrong place to do it.
joe
On Sun, 9 Sep 2007 13:29:10 +0100, "Sebastian Warmuz" <sebastian@xxxxxxxxxxx> wrote:
Thx Scott And Joseph.Joseph M. Newcomer [MVP]
Sorry for my stupid questions but I already started to learn threads. I made
everythign like You said and now everything works fine. But I have only one
small problem....
In the method I am creating a therad I have to obtain that thread is
finished. This thread will make a backup of some files and after job is done
it will continue to lauch application
void CMyApp::OnInitInstance()
{
// 1. init etc,
// 2. make backup in thread displaying progress
// 3. if backup made do the res
}
But the problem is that point 3 is started when backup thread is not yet
finished.... How o resolve it ?
Regards
Uzytkownik "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> napisal w
wiadomosci news:uU$zW6l8HHA.484@xxxxxxxxxxxxxxxxxxxxxxx
"Sebastian Warmuz" <sebastian@xxxxxxxxxxx> wrote in message
news:O2KuoVk8HHA.396@xxxxxxxxxxxxxxxxxxxxxxx
Hi I am copyying file in a thread, meanwhile I am displaying a disloag
with progress bar, the problem is that message box is displayed before
copying is finished. Can anyone help me ??
Your code started the copying thread, then immediately displayed the "Copy
Finished" message box. That is why the message box is displayed. Don't
call the message box in the same function that starts the thread. Just
return to MFC after you start the thread so the GUI can process messages
while the copy runs.
Add a message handler in the main GUI :
ON_MESSAGE(WM_USER_THREAD_COPY_FINISHED, OnCopyFinished)
and display the message box in this message hander. For some reason you
posted this message to the copy thread, but you should post it to the GUI
main window and create all of your GUI displays in the main thread.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Waiting to thread exit
- From: Sebastian Warmuz
- Re: Waiting to thread exit
- From: Scott McPhillips [MVP]
- Re: Waiting to thread exit
- From: Sebastian Warmuz
- Waiting to thread exit
- Prev by Date: Re: Waiting to thread exit
- Next by Date: Re: About CGdiObject::UnrealizeObject()
- Previous by thread: Re: Waiting to thread exit
- Next by thread: Re: Waiting to thread exit
- Index(es):
Relevant Pages
|