Re: [BLACKBOX] Program freezes when window loses focus

From: [at]} <Chris>
Date: Wed, 16 Mar 2011 08:48:16 +1030

----boundary-LibPST-iamunique-653528017_-_-
Content-type: text/plain

________________________________

        From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
Stephen R. Troy
        Sent: Wednesday, 16 March 2011 7:50 AM
        To: BLACKBOX{([at]})nowhere.xy
        Subject: Re: [BLACKBOX] Program freezes when window loses focus
        
        
                No, sorry, that's not it. I said "display window" in the
same sense as you said "form"; i.e. I'm already doing the better way you
suggest, using Dialog.Update, and watching the program execute. However, if
I do something to lose focus on the display form, such as click mouse-click
elsewhere, or start another program outside BlackBox, the program freezes.
It is not executing an infinite loop, because I am too old a programmer for
that, I put traps to halt loops that run an excessive number of times; i.e.
an excessive number of iterations is always one of several exit conditions.



-----------------------------------------------------
        
This sounds very similar to a problem reported here in Dec 2009.

-----------------------------------------------------
The problem:
>I have a long running command (about 15 min) and in order to show that
>it makes progress, I call Dialog.ShowStatus, which displays a message
>in the status bar at the bottom of the application window.
>
>This works fine as long as there is no event being sent to the
>application e.g. by clicking the mouse or pressing a key.
>If such an event occurs, the status bar stops being updated after about
>5 seconds and the application appears to be completely frozen until the
>command terminates.
>This confuses the users and it confuses even me.
>
-----------------------------------------------------
My response:

AFAIK, the proper solution for this sort of problem is to use multiple /
background threads. However, a less elegant but easier and possibly
effective solution is to periodically process the Windows Message queue. The
following example should help you get started:

MODULE TestLong;

IMPORT Dialog, Strings, Win := WinApi;

PROCEDURE ProcessMessages;
  VAR msg: Win.MSG; res: INTEGER;
BEGIN
  WHILE Win.PeekMessage(msg, 0, 0, 0, Win.PM_REMOVE) # 0 DO
    res := Win.TranslateMessage(msg);
    res := Win.DispatchMessageA(msg)
  END
END ProcessMessages;
        
PROCEDURE Do*;
  VAR i, j: INTEGER; s: ARRAY 20 OF CHAR; BEGIN
  FOR i := 0 TO 300 DO
    ProcessMessages;
    FOR j := 0 TO 10000000 DO
    END ;
    Strings.IntToString(i, s);
    Dialog.ShowStatus("msg " + s)
  END
END Do;

END TestLong.

P.S. My system must be faster than yours - I had to increase the j loop by a
factor of 10 to 100000000 to actually test it!
-----------------------------------------------------

So try putting a call to ProcessMessages at a suitable position in your
processing loop so that it will get called at least a few times a second,

Regards,
Chris Burrows

CFB Software
Astrobe v3.3: ARM Oberon-07 Development System
http://www.astrobe.com


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-653528017_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIF9fX19fX19fX19fX19fX19fX19fX19fX19fX19f
X19fXHBhcg0KXHBhcg0KXHRhYiBGcm9tOiBCbGFja0JveCBbbWFpbHRvOkJMQUNLQk9YQExJU1RT
Lk9CRVJPTi5DSF0gT24gQmVoYWxmIE9mXHBhcg0KU3RlcGhlbiBSLiBUcm95XHBhcg0KXHRhYiBT
ZW50OiBXZWRuZXNkYXksIDE2IE1hcmNoIDIwMTEgNzo1MCBBTVxwYXINClx0YWIgVG86IEJMQUNL
Qk9YQExJU1RTLk9CRVJPTi5DSFxwYXINClx0YWIgU3ViamVjdDogUmU6IFtCTEFDS0JPWF0gUHJv
Z3JhbSBmcmVlemVzIHdoZW4gd2luZG93IGxvc2VzIGZvY3VzXHBh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uICA=
----boundary-LibPST-iamunique-653528017_-_---
Received on Tue Mar 15 2011 - 23:18:16 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:16 UTC