Helper Loop timing
What’s a Helper Loop?
A Helper Loop, in the DQMH framework context, is the name given to a loop executing code periodically through the Timeout case of an event structure.
You can implement a Helper Loop even if you are not using the DQMH framework |
A Helper Loop is composed of the following elements:
-
A while loop.
-
An event structure with the
Timeout
case. -
A non-negative value set to the
Timeout
input of the event structure.
The code you want to execute periodically is put into the Timeout
case.

if you want to explore the Helper Loop concept and why it’s a better solution than self-messaging, take a look at this excellent article |
How the the Timeout case execution is triggered
The Timeout
case is executed when no events are detected during the time set to the Timeout
input of the event structure.
The Timeout
counting starts when the event structure is called.
The time spent executing code in the Timeout
case and after the event structure execution is delaying the next Timeout count.
Any event occurring reset the Timeout count.
The Timeout
case can be rarely (or never) executed when the event structure handles other events.
That’s why, setting a value to the Timeout
input of the event structure is not enough to get a steady execution period of the Timeout
case.
How the Helper Loop timing API ensure a steady period
Using the API to time your event structure allows you to:
-
get a steady execution period in any case.
-
know you are late executing the
Timeout
case.
The example provided demonstrates the different issues that can occur.

The Helper Loop are set to execute the Timeout case every 250 ms
|
Timeout reset
1 | Hitting the Reset Timeout button triggers an event in the event structure. |
2 | In the incorrectly timed Helper Loop, the execution time is impacted by the reset. |
3 | In the correctly timed Helper Loop, the Timeout value is modified to take account of the reset. |
4 | The execution time is not impacted. |

You can see that the incorrectly timed Helper Loop executes fewer times than the correctly timed one. |
Timeout case time execution
1 | We simulate a code execution taking 100 ms. |
2 | In the incorrectly timed Helper Loop, the execution time is impacted by this code execution time. |
3 | In the correctly timed Helper Loop, the Timeout value is modified to take account of the time spent since the beginning of the Timeout case execution. |
4 | The execution time is not impacted. |

Late Timeout case execution
Even if you time your Helper Loop correctly, you can get late execution of the Timeout
case.
Indeed, if the code that executes after the beginning of the Timeout
case execution takes more time than the desired period, there’s nothing to do.
The API provides a simple way to monitor if your Helper Loop runs at the expected period.
1 | We simulate a code execution taking more than the desired period. |
2 | The period execution cannot be reached. |
