🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi
Article #159

Re: Problem with message dispatching in thread

#159
From: Peter Below (TeamB)
Date: Mon, 26 Jan 2004 18:59
38 lines
2600 bytes
In article <40151062$1@newsgroups.borland.com>, Magnus Oskarsson wrote:
> I have a thread that spends most of its time waiting for various events
> and/or input in its message queue. Support for the latter was added so that
> it would be possible to create objects such as timers in code executed in
> this thread. It turns out that the thread receives a number of messages even
> when no objects such as timers are created, and that dispatching these
> messages occasionally causes an access violation. The messages in these
> cases were WM_DEVICECHANGE with wParam 7 and lParam 0. The key code looks
> like this:
> 
> PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE); {initialize the message queue}
> ....
> SignaledObject := MsgWaitForMultipleObjects(EventCount, HandleArray, False,
>   INFINITE, QS_ALLINPUT);
> case SignaledObject of
>   ...
>   {cases for various signaled synchronization objects}
>   ...
>   else {input in the message queue}
>     while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
>       DispatchMessage(Msg);
> end;
> 
> What is it that is wrong with this code? 

You may want to check Msg.Hwnd and only call DispatchMessage if the window 
handle is > 0. That should be safe enough. But there is actually no point in 
using timers inside a secondary thread, just use a appropriate timeout on the 
wait...


--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Technical Details
Message-ID: <VA.0000a90a.004f3154@nomail.please>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <40151062$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f94dd,a9e8600237d4d3c8
X-Google-Attributes: gidf94dd,public
X-Google-ArrivalTime: 2004-01-26 11:10:03 PST
Date: Mon, 26 Jan 2004 19:59:46 +0100
Newsgroups: borland.public.delphi.nativeapi
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va
Organization: TeamB
Message-ID: <VA.0000a90a.004f3154@nomail.please>
Subject: Re: Problem with message dispatching in thread
From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com>
Reply-To: 100113.1101@compuXXserve.com
References: <40151062$1@newsgroups.borland.com>
NNTP-Posting-Host: 62.226.187.154
X-Trace: newsgroups.borland.com 1075143473 62.226.187.154 (26 Jan 2004 10:57:53 -0700)
Lines: 40
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail