🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11594

Re: WaitForMultipleObjects in TThread

#11594
From: Oliver Rutsch
Date: Fri, 30 Jan 2004 11:46
35 lines
2441 bytes
Hi Kristoffer,

>>Use WaitForMultipleObjects and define an array of events (a terminate
>>event, your origin event ...). When the wait returns, react on the
>>WAIT_OBJECT_0 ... WAIT_OBJECT_X return values and let your thread end
>>gracefully if it receives the terminate event.
> 
> 
> Thanks, but how do I get the quit message to signal my terminate event?
> Especially since I'm stuck in the WaitForMultipleObjects call. It's probably
> something simple...

I don't know your program, but if you receive a WM_QUIT in your main 
thread, then maybe you have a OnClose handler or something like this. In 
this function get a handle to the terminate event of your thread and set 
it to signaled, for example:

void __fastcall MyForm::OnClose(TObject *Sender)
{
	SetEvent(MyThread->GetTerminateEventHandle());
	MyThread->WaitFor();
	...
}


I wouldn't post a message like WM_QUIT to the thread (if it has it's own 
message queue) because you can't wait with the WaitFor... functions and 
at the same time wait for a windows message.

Bye,

-- 
Dipl. Ing. Oliver Rutsch
EMail: Name:orutsch domain:sympatec.com
Sympatec GmbH Germany
Technical Details
Message-ID: <1075463350.186832@post.sympatec.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40191ff7$1@newsgroups.borland.com> <1075389099.199618@post.sympatec.net> <401a0744$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,2e632a3799f22e8b
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-01-30 04:09:48 PST
Date: Fri, 30 Jan 2004 12:46:25 +0100
From: Oliver Rutsch <nospam@sympatec.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113
X-Accept-Language: en-us, en, de-de
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: WaitForMultipleObjects in TThread
References: <40191ff7$1@newsgroups.borland.com> <1075389099.199618@post.sympatec.net> <401a0744$1@newsgroups.borland.com>
In-Reply-To: <401a0744$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Organization: Ye 'Ol Disorganized NNTPCache groupie
Message-ID: <1075463350.186832@post.sympatec.net>
Cache-Post-Path: post.sympatec.net!unknown@rutsch.tksympatec
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
NNTP-Posting-Host: 217.6.163.138
X-Trace: newsgroups.borland.com 1075463368 217.6.163.138 (30 Jan 2004 03:49:28 -0700)
Lines: 35
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail