Article View: borland.public.cppbuilder.nativeapi
Article #16226Re: Unblock thread with PostMessage()?
From: Nick B. Cassos
Date: Wed, 28 May 2003 05:37
Date: Wed, 28 May 2003 05:37
43 lines
2591 bytes
2591 bytes
On Wed, 28 May 2003 10:28:05 +1000, Peter Stefanos
<peterATpennywiseDOTcomDOTau> wrote:
>Nick,
>
>Your suggestion for the queue is fine for not holding up the thread. I
>had already considered this but then you would need something like a
>timer checking the queue for events. I need to know about events quickly
>and having a timer checking every millisecond or so doesn't seem to be
>the most elegant way of doing it.
>
No need for a TTimer. You could use an event property, like "OnEvent".
Since the most important thing here is not to mess up the worker
thread with the User Interface, the "OnEvent" handler could only set
up a boolean variable, like "EventAvailable" and return immediately.
The main thread (responsible for the GUI) could actually handle it in
- for example - the OnIdle handler:
void __fastcall TMainForm::MyIdle(TObject* Sender, bool &Done)
{
if (EventAvailable)
{
EventAvailable = false;
while (PopEvent())
{
HandleEvent();
}
}
}
Of course I am just guessing here, because I do not know the inner
workings of your thread, how critical it is, etc. I am just proposing
a way to avoid tighting a worker thread to the main one. If your
worker thread needs immediate attention then you still could handle
everything in the "OnEvent" handler * except * any action requiring
user intervention. If such a case occurs, you could still use the
above trick.
--
Nick B. Cassos
Technical Details
Message-ID:
<d5i8dv86p6uqpva24enmom8eoe1h1n9q6l@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3ed2f25e@newsgroups.borland.com> <0fu6dv066f6u49kga1ljaqt8pes48qve8q@4ax.com> <3ed402a7@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,679ed0dfb63f4be3 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-27 23:11:20 PST From: Nick B. Cassos <nbc@no_spam.ath.forthnet.gr> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Unblock thread with PostMessage()? Date: Wed, 28 May 2003 08:37:01 +0300 Message-ID: <d5i8dv86p6uqpva24enmom8eoe1h1n9q6l@4ax.com> References: <3ed2f25e@newsgroups.borland.com> <0fu6dv066f6u49kga1ljaqt8pes48qve8q@4ax.com> <3ed402a7@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 213.16.148.219 X-Trace: newsgroups.borland.com 1054100229 213.16.148.219 (27 May 2003 22:37:09 -0700) Lines: 43 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!cyclone.bc.net!logbridge.uoregon.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail