The class Timer (gb) implements a Timer object. A Timer object is to be understood as a clock that triggers events with each clock pulse. The time between each clock pulse is determined by the value of the Delay property (clock pulse time in milliseconds).
The Timer class has only two properties:
Property | Data type | Description |
---|---|---|
Delay | Integer | Returns the number of milliseconds between timer events or sets the number of milliseconds between clocks. |
Enabled | Boolean | Starts the timer with Timer.Enabled = True or determines whether the timer is active. A deactivated timer can no longer trigger timer events. |
Table 20.3.0.1.1 : Properties of the Timer class
The Timer class has three methods, the description of which can be found in the following table:
Method | Description |
---|---|
Start | The timer is started. This has the same effect as Timer.Enabled = True. |
Stop | The timer is stopped. This has the same effect as Timer.Enabled = False. |
Trigger() | Timer.Trigger() triggers the Timer_Timer() event on the next iteration of the event loop. This method is useful for executing the event handler “later” - at least after the current stack of function calls or at the next explicit call to WAIT. |
Table 20.3.0.2.1 : Methods of the class Timer
There is exactly one event for the class Timer → Timer_Timer(). This event is triggered every time the cycle time specified via Timer.Delay has elapsed.
Note that the cycle time is at least Timer.Delay. There is generally no guarantee - depending on the hardware used and and the operating system and its configuration - that the event handler will be executed “close in time”.
The following is a compilation of selected fields of application for Timer objects from various demonstration projects in the online book:
This concept has proven successful when using a timer:
The timer function Timer() - which is unrelated to the class Timer - specifies the number of seconds that have elapsed since the programme start. The function value is of the float data type. The function uses the system clock.
With the following source code excerpt
Dim fZeitdifferenz as Float fZeitdifferenz = Timer Print "Sekunden seit Programm-Start = ";;fZeitdifferenz;;" Sekunden"
… the number of seconds elapsed since the programme start is displayed in the console of the Gambas IDE:
Zeit seit Programm-Start = 17,8296689987183 Sekunden
The function can be used, for example, to measure runtime when comparing search or sort algorithms or for selected, time-intensive procedures.
Chapter