class PTimer |
A class representing a system timer.
Overrides from class PObject
Access functions
Operations
Comparison functions
Run Time Type functions
I/O functions
A class representing a system timer. The time interval ancestor value is the amount of time left in the timer.A timer on completion calls the virtual function OnTimeout(). This will in turn call the callback function provided by the instance. The user may either override the virtual function or set a callback as desired.
A list of active timers is maintained by the applications PProcess instance and the timeout functions are executed in the context of a single thread of execution. There are many consequences of this: only one timeout function can be executed at a time and thus a user should not execute a lot of code in the timeout call-back functions or it will dealy the timely execution of other timers call-back functions.
Also timers are not very accurate in sub-second delays, even though you can set the timer in milliseconds, its accuracy is only to -0/+250 ms. Even more (potentially MUCH more) if there are delays in the user call-back functions.
Another trap is you cannot destroy a timer in its own call-back. There is code to cause an assert if you try but it is very easy to accidentally do this when you delete an object that contains an onject that contains the timer!
Finally static timers cause race conditions on start up and termination and should be avoided.
SetInterval(120000) SetInterval(60000, 60) SetInterval(60000, 0, 1) SetInterval(0, 60, 1) SetInterval(0, 0, 2)
Please note that the application should not execute large amounts of code in this call back or the accuracy of ALL timers can be severely impacted.
The default behaviour of this function is to call the PNotifier callback function.
Note that even though this function returns milliseconds, the value may jump in minimum quanta according the platforms timer system, eg under MS-DOS and MS-Windows the values jump by 55 every 55 milliseconds. The Resolution() function may be used to determine what the minimum time interval is.
Alphabetic index HTML hierarchy of classes or Java