Class: cIdleHandler

Properties  Events  Methods    Index of Classes

Used to create objects that generate idle events. Can be used in place of timers



Library: Windows Application Class Library

Package: none (class defined in runtime)


cIdleHandler is used to create objects that generate events on a periodic basis. Unlike the cTimer class, which fires events on a timed basis, the cIdleHandler generates an event when the user interface processing loop has finished processing requests. The idle event is sent when the application is about to "go idle". Idle timers have the advantage that the events are only triggered when required (after UI activity) and these events are only triggered when the program is idle.

The cIdleHandler has a very simple interface. pbEnabled determines if idle events should be triggered, and, if enabled, the OnIdle event is sent to the object.

By default, pbEnabled is set to false, therefore the OnIdle events are not sent. It is the programmer's responsibility to turn enable and disable the idle handler as needed. Do not assume that they will be automatically enabled when their parent is activated and, more importantly, do not assume that they are disabled when the parent object is deactivated.

If an idle handler object is enabled, it will be suspended if a modal object is invoked and resumed when the modal object is closed. If you wish you can create additional idle handler objects within the modal object. Again, note that you must enable and disabled idle handlers yourself.

You may create as many idle timers as you want.

The following sample shows how create a button that is only enabled when changes exist in the view. It contains an idle handler, which will set the button's enabled_state of the button as needed. The idle timer is enabled when the button as activated and it is disabled when the button the disabled. Once enabled, the OnIdle event will send the TestEnabled message to the button, which will enable / disable itself as needed.

Object oSaveButton is a Button
    Set Location to 167 220
    Set Label to "Save"

    // fires when the button is clicked
    Procedure OnClick
       Send Request_Save        
    Object oIdleHandler is a cIdleHandler
       Procedure OnIdle
           Delegate Send TestEnabled
    // enable the button if the main DDO is changed
    Procedure TestEnabled
       Boolean bSave
       Handle hoServer
       Delegate Get Main_DD to hoServer
       If hoServer Begin
           Get Should_Save of hoServer to bSave
       Set Enabled_State to bSave
    // enable the idle handler timer when the button is activated
    Procedure Activating
       Forward Send Activating
       Set pbEnabled of oIdleHandler to True

    // disable the idle handler when the button is deactivated
    Procedure Deactivating
       Set pbEnabled of oIdleHandler to False
       Forward Send DeActivating