Article View: borland.public.cppbuilder.nativeapi
Article #16221Re: Unblock thread with PostMessage()?
From: Peter Stefanos
Date: Wed, 28 May 2003 00:28
Date: Wed, 28 May 2003 00:28
51 lines
2774 bytes
2774 bytes
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. This is why I would like an example of using PostMessage() within a class, if that is indeed a way of doing it. i.e. Event | PostMessage() (main thread in message loop) | call "Event Dispatcher" | call users event handler. Regards, Peter. Nick B. Cassos wrote: > On Tue, 27 May 2003 15:06:17 +1000, Peter Stefanos > <peterATpennywiseDOTcomDOTau> wrote: > > >>... >>I have read a few postings about using PostMessage() (no pun intended) >>but I do not know how to implement it without putting the message >>handler method and message map in the users form class manually. >>Any ideas? Is this the best way to do this? Is there a simpler way? >>... > > > You can implement your own queue. A simple TStringList may be enough, > using the Objects property to hold event types, for example, and the > Strings property to hold information. For less simple structures you > could use a TList or better a TThreadList. > > Protect your "queue" with a TCriticalSection (if it is not the > TThreadList) and offer the user some functions to handle it (e.g. > PopEvent()) > > No need to use PostMessage or Synchronize(), and your thread can keep > working. You may also offer a maximum number of Events that the queue > may hold, before your thread goes for sleep, etc. >
Technical Details
Message-ID:
<3ed402a7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3ed2f25e@newsgroups.borland.com> <0fu6dv066f6u49kga1ljaqt8pes48qve8q@4ax.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 17:59:49 PST Date: Wed, 28 May 2003 10:28:05 +1000 From: Peter Stefanos <peterATpennywiseDOTcomDOTau> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-au, en-us MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Unblock thread with PostMessage()? References: <3ed2f25e@newsgroups.borland.com> <0fu6dv066f6u49kga1ljaqt8pes48qve8q@4ax.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 202.45.113.90 Message-ID: <3ed402a7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1054081703 202.45.113.90 (27 May 2003 17:28:23 -0700) Lines: 52 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail