"J French" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Sun, 21 May 2006 08:54:09 +0100, "Anthony Jones"
> <(E-Mail Removed)> wrote:
>
>
> <snip>
>
> >Oops I didn't spot that WaitMessage function. It might be useful to the
OP
> >to provide it's declare (simple though it might be I didn't spot it and
it's
> >not obvious its an API call):-
>
> >Private Declare Function WaitMessage Lib "user32" () As Long
>
> Since the original post was a jiggered form of Shell And Wait from the
> KPD All API Guide, I figured that the OP would realize that
> WaitMessage is an API
>
> >However I can't see how the termination of the launched process would
> >generate a windows message to cause waitmessage to return.
>
> It seems it does
> - when an App unloads it creates a bundle of activity within Windows
> - also Windows knows very well which thread launched the App
> - I just found that it is reliable
>
Hmm.. seems a bit wolly. You may be right. As a process tears itself down
it may remember what thread launched it. It may look for a window message
pump queue thingy on that thread (does every thread in windows have on
these? I don't think so). It may decide to put a message in that queue to
the effect that 'a process you created is now finished'.
It would be nice know for sure that that is what is happening. At the
moment I think it's more likely that is works simply because some messages
will be passing through anyway.
> >> >It makes the app responsive to user events which may be a good thing.
> >>
> >> Sure is
> >>
> >> >OTH the rest of the code in the app needs to take care not to
interfere
> >with
> >> >this unfinished business or use information from this activity until
it's
> >> >finished.
> >>
> >> Better that, than have a totally frozen App that cannot even re-paint
> >> itself
>
> >Agreed but there is more work that needs to be done and I still don't
think
> >a DoEvents loop is the approach to take.
>
> Why not ?
> a) it is not hammering the processor
> b) it is not 'blocking' the App
>
How many of these loops would you want in your app? What if the process you
launched never dies, does this loop stay inplace.
> Anyway an App's Window Message queue is just a loop using a variation
> of WaitMessage
>
> // Start the message loop.
>
> while (GetMessage(&msg, (HWND) NULL, 0, 0))
>
> {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
>
Yeah but one of these is already there do we want to create others also?
>
>
> >> >If the created process is hung then this look never exits so an
> >additional
> >> >counter might be needed to terminate the loop after certain period has
> >> >elapsed.
> >>
> >> You are right about that, but that was not the question
>
> >Yes the OP wasn't interested in any of this. It's a little ambiguous but
> >appears the OP seems to be wondering whether launching the process in
this
> >manner may be the reason it is freezing (the called process). A
secondary
> >affect being that the calling process freezes.
>
> <quote>
> I believe the use of the automation in this manner may be causing the
> application to freeze on some machines. It causes it and its parent
> application to freeze as well.
> </quote>
>
> The code is deliberately freezing the Calling App until the Called App
> returns
> - it has nothing to do with the Called App, once that is running the
> calling App has no influence
>
> >The answer is I doubt this manner of launching the process is causing it
to
> >freeze but it's difficult to tell.
>
> It is definitely freezing the Caller
> - which is pretty darn silly for a 3+ minute process
>
Perhaps I've read the question wrong.
> >> If you want to do that then activate a normal VB Timer with a interval
> >> of say 1 sec to act as a Message pump
>
> >> That way the App will get at least 1 msg per sec, and the code in the
> >> loop can decide when to cop out.
>
> >> You need to have a serious look at what WaitMessage does, it is a
> >> fascinating beast
> >> - and extremely efficient at keeping down unnecessary processing
>
> >> It can be used for all sorts of tasks, my favourite is for totally
> >> hijacking the Windows loop
>
> >I think in this case a better design would be to launch the app but not
loop
> >at all.
>
> There are two types of Looping
> a) inefficient looping
> -using pure DoEvents that raises CPU usage to 100%
> b) efficient looping that responds immediately to Windows
>
c) Don't bother
> >Use a timer to check whether the process handle has been signalled.
>
> That is a possibility
> - in this case I would use an AX Exe and run the process off its
> internal thread
> - or use a normal Exe and set up a communications system
>
> Sometimes Waiting is sensible
> - especially if there is not much you can do until the thing comes
> back with a result
>
Agreed
> >Modify the parent app to ensure invalid actions are not taken whilst this
> >secondary process is operating.
>
> Dead easy, a Modal Form with an Abort button
>
Ah now it makes sense. Your WaitMessage/DoEvents loop coupled with this
should work nicely.
> >TBH I've never come across a problem that might be solved using a
DoEvents
> >loop that couldn't be better solved without one. Especially if the
> >developer is happy dipping into the windows API.
>
> I am trying to explain to you that
>
> While Something
> WaitMessage
> DoEvents
> Wend
>
> Is NOT a DoEvents Loop
> - it is the equivalent of popping up a Modal Form ( and you can be
> sure that is how Modal Forms work )
>
> As I said before, you would be wise to look into the implications of
> WaitMessage
Doesn't look like I need to. What else is there to learn that you haven't
already explained
> - a lot of VB programmers don't understand it
I think it's more like never heard of it. I hadn't and I've been doing VB
for more years than I care to admit. (although not a great deal of UI
work).