Axaptapedia is now maintained by AgileCadence For more information please click here.

Using Timer

From Axaptapedia
Jump to: navigation, search

If you want perform a periodic task you can use batch processing, but there is another option to perform local fast periodic tasks - timers.

You can call the setTimeOut function in forms or client-side classes like this: <xpp>

this.setTimeOut("updateRealTime", 1000, FALSE);



  • "updateRealTime" - Name of method to call.
  • 1000 - wait time in milliseconds
  • true - means that time should only be measured while the program is idle.

This example is taken from tutorial_Timer form

Lets see at the updateRealTime source: <xpp>

 void updateRealTime()
   _realTimer = this.setTimeOut("updateRealTime", 1000, FALSE);

</xpp> it performes some useful action (realTime.value(timeNow());) and then sets the timeout again, so the action will be performed every second.

Another pattern of using timers is to perform something in the background or as an interruptable task. The clearest example is SysAotFind form which performs a search through the AOT.

The pattern is as follows:

  • declare a "stop flag" in your object
  • divide your task into small iterative steps
  • execute each step in the timeout function
  • set the timeout again at the end of the timeout function, if the stop flag is not set
  • when user presses the stop button, set the stop flag to true. Execution will stop at the end of the next cycle.

see \Forms\SysAotFind\Methods\nextTreeNode for example