Tips   >   Externals   >   Timer Object
The first time I tried to use the timer object it took a while to find because it wasn't loaded. Review the topic on
if the object doesn't show up in your external components treelist.To use the timer object you first create an object class which has the timer object as its superclass.
Once the timer object class is created, you can instantiate it using an object data type variable. Depending on the purpose you can use a task variable, class variable, or instance variable to instantiate your object class which has the timer object as its superclass.
Your
Click the object class will have several properties and methods which are reviewed below. button to open a window which demonstrates an oTimerDemo object class and a technique for adding an observer to a timer object. The observer is notified each time a $timer message is received by the timer object.The timer object $autoreset property can be set to kTrue or kFalse.
If set to kFalse the timer object will send a $timer message once and then stop. If set to kTrue the timer object will continue to send $timer messages at the interval specified by the $timervalue and $useseconds properties until it is sent a $stoptimer message.The timer object $reentrant property can be set to kTrue or kFalse.
If set to kTrue the timer sends a $timer message and immediately restarts the timer without waiting for the $timer method to execute.
If set to kFalse the timer sends a $timer message and waits for the $timer method to complete before restarting the timer.The timer object $useseconds property can be set to kTrue or kFalse.
If set to kTrue the unit of measure for $timervalue will be seconds. If set to kFalse the unit of measure will be milliseconds.Some Omnis developers have reported that a timer object initiated method will crash Omnis Studio if the timer object initiated method kicks in when another Omnis Studio method is executing.
To prevent this from happening you can use the sys(90) function to check the number of methods in the method stack and abort running the timer object method if other methods are running at the same time.
Place the following code at the start of your $timer method:
; Check the number of methods currently in the method stack.
Calculate MethodStackLineCount as sys(90)
If MethodStackLineCount<>1
; A method other than this one is currently running.
; Restart the timer object if it is not $reentrant.
If $cinst.$reentrant=kFalse
Do $cinst.$starttimer()
End If
Calculate FlagOK as kTrue
Else
; No other methods are in the method stack.
; Run the timer object method initiated code.
Breakpoint
End If
Quit method FlagOK
The sys(9) function does not work for web client requests running in a thread of the multi-threaded server.