# IupTimer

Definition: | include pGUI.e Ihandle res = IupTimer(cbfunc func=NULL, integer msecs=0, boolean active=true)
Description: | Creates a timer which periodically invokes a callback when the time is up. func: a callback address, usually specified as Icallback("name"). msecs: an interval in miliseconds. active: true or false, you can change the "RUN" attribute later. Each timer should be destroyed using IupDestroy.
pwa/p2js: | Supported.
Example: | A generally useful example of using a timer to allow any currently active drawing processes to abandon before starting a new one can be found in demo\rosetta\VoronoiDiagram.exw. While relatively simple, it can make a huge difference to responsiveness (and in that particular case, not crashing). In one case (Conway’s game of life) setting a timer before the IupShow() prevented the latter from returning for quite some time, and perhaps not until Escape had been keyed, so from that experience I strongly recommend not creating a timer until after an initial IupShow() has returned, and probably after setting any RASTERSIZE to NULL, otherwise it may misbehave - in the program just mentioned two things went wrong: Escape had to be keyed twice to close the window, and the canvas did not resize properly, and both were fixed simply by moving the IupTimer() creation down three lines.
Attributes: |
TIME | The time interval in milliseconds. In Windows the minimum value is 10ms.
RUN | Starts and stops the timer. Possible values: "YES" or "NO", IupSetInt() with true/1/false/0 also works, as does IupToggleInt(). Returns the current timer state. If you have multiple threads start the timer in the main thread.
WID | (read-only): Returns the native serial number of the timer. Returns -1 if not running. A timer is mapped only when it is running.
Callbacks: |
ACTION_CB | function action_cb(Ihandle ih) ih: identifier of the element that activated the event. Returns: IUP_CLOSE will be processed, but desktop/Phix only, ignored within pGUI.js. (My strongest advice would be to explicitly invoke IupHide() with the dialog you mean, in preference to having the system guess which one, along with future readers of your code, which may very well include yourself.) Called every time the defined time interval is reached. To stop the callback from being called simply stop the timer with RUN=NO. Inside the callback the attribute ELAPSEDTIME returns the time elapsed since the timer was started (since 3.15).