Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disabling message pump while scripts are executing

31 views
Skip to first unread message

Oliver Bock

unread,
Jan 6, 2010, 7:39:29 PM1/6/10
to
JScript pumps my windows message loop when executing long-running
scripts. This causes problems for me because I end up with recursive
WM_PAINT calls. I could block this with IMessageFilter (I think), but I
was hoping there was a nicer way of telling JScript/Script Host not to
do it.


Oliver

Paul Baker [MVP, Windows Desktop Experience]

unread,
Jan 13, 2010, 9:14:03 AM1/13/10
to
That's interesting.

I wonder if it is in any way related to my own odd script problem posted to
microsoft.public.programmer.messaging:

Sporadic CDO failure when called in multithreaded VBScript:
http://groups.google.com/group/microsoft.public.win32.programmer.messaging/browse_thread/thread/fe27dd8ad529a4a9

The IMessageFilter documentation says that it "Provides COM servers and
applications with the ability to selectively handle incoming and outgoing
COM messages while waiting for responses from synchronous calls.". I am
guessing that this refers only to the following kind of message, which
applies only in an STA anyway:

INFO: OLE Threads Must Dispatch Messages
http://support.microsoft.com/kb/136885

Who the heck is processing arbitrary queued messages? JScript? IMO, message
processing should not be done by anything except the code that created the
thread. You seem to be thinking the same thing, you call it "[my] message
loop" like you own it. And you do! In Borland Delphi code, I commonly see
"Application.ProcesssMessages" used as a trick for doing something blocking
while still being responsive to the user. For example, when there is a
progress dialog and blocking call in the same thread as the main UI. It's a
crappy thing to do. It actually is unreliable for making the thread
responsive and it can cause reentrancy issues or allow the user to do
something that should be disabled, because the caller assumed it was
blocking. In Borland Delphi, it does not help that the VCL is not
thread-safe, encouraging people to throw everything in the main thread.
There is also a TThread.Synchronize method that is billed as a magical
thread safety fix, but all it really does is force something to be called in
the main thread during its message loop.

Paul

"Oliver Bock" <oliverPlea...@g7.org> wrote in message
news:%23FYHhHz...@TK2MSFTNGP02.phx.gbl...

Paul Baker [MVP, Windows Desktop Experience]

unread,
Feb 10, 2010, 1:40:29 PM2/10/10
to
Oliver,

IMessageFilter will help you, but it will only see the messages found in the
queue by COM in an STA. For example, in CDO I encountered another message
loop and there is nothing I can do about it (grr). My CDO problem is
resolved, if you want to take a look at my posts.

It is almost certainly COM, not the script host/engine, that is dispatching
the messages.

There is no "nice" way when you're dealing with an STA. You could try
another threading model.

Paul

"Paul Baker [MVP, Windows Desktop Experience]"
<paulrich...@community.nospam> wrote in message
news:%23qn4qqF...@TK2MSFTNGP04.phx.gbl...

0 new messages