Re: [BLACKBOX] Long running command and Dialog.ShowStatus

From: [at]} <Chris>
Date: Thu, 3 Dec 2009 17:33:33 +1030

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

>-----Original Message-----
>From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
>Josef Templ
>Sent: Thursday, 3 December 2009 4:49 PM
>To: BLACKBOX{([at]})nowhere.xy
>Subject: [BLACKBOX] Long running command and Dialog.ShowStatus
>
>Hi Everybody!
>
>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.
>

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!

Regards,
Chris

--
Chris Burrows
CFB Software
Armaide: ARM Oberon-07 Development System
http://www.cfbsoftware.com/armaide.htm
----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1217423967_-_-
Content-type: application/rtf
Content-transf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vZnR3YXJlXHBhcg0KQXJtYWlkZTogQVJNIE9iZXJvbi0wNyBEZXZlbG9wbWVudCBTeXN0ZW1c
cGFyDQpodHRwOi8vd3d3LmNmYnNvZnR3YXJlLmNvbS9hcm1haWRlLmh0bVxwYXINClxwYXINClxw
YXINCi0tLS1ccGFyDQpUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJT
SUdOT0ZGIEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hcfX0AdC1I
----boundary-LibPST-iamunique-1217423967_-_---
Received on Thu Dec 03 2009 - 08:03:33 UTC

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