Timers and other code

Heres the issue and code can be provided per request but quite messy and all over different methods:

Basically I am using timers to run a series of picture slides (e.g., timer 1 shows pic 1 (full screen) which is then replaced by pic 2 when timer 2 starts).

I am also recording when people press a button during this picture slide portion (e.g., press “h” when pic 3 is shown).
This is done by using something along the lines of “starttime = milliseconds/1000 at timer 1” and “stoptime = milliseconds/1000 during keydown” or if I am recording time to go from timer “x” to timer “y”, "stoptime=milliseconds/1000 at timer “y”. Followed by recordedtime = stoptime - starttime

The timeframe for the timers and this pic slide portion is about 100-300 milliseconds per timer (and I am aware that they are not fully accurate and have read the timer documentation page).

There seems to be a gap (about 50 milliseconds) where if a timer starts and a key is pressed (i.e., 2 actions at once~ish), no information is recorded.
Here is an example plot of the histogram where x axis is time and y axis is frequency of button pressed at that time.

FYI, the button press action (i.e., keydown enabled) starts at the same time as time recording starts) and timer “x” starts at the 350 mark so from 370-410, nothing is recorded and any button pressed inputs are rerecorded after 410 (which may explain why there are so many afterwards, excluding normal distribution curves).

If I am understanding correctly, it seems like the keydown code is halted to let the timer start and autoresubmits the keydown inputs after the timer code runs.

If anyone can clarify and/or help solve this issue either by assisting in a different format to record or elsewise, I’d greatly appreciate it fellow coders! Any and all help is much welcomed and appreciated!

do you use same variables again or does a active timer action event overwrite a start measurement?
you could write a little stopwatch class to collect more informations when what is happens.
i would log all and then review this history.
have you blocked a key input somehow that it is not possible to measure?

1 Like

Yup! I have done exactly as you said!

I created several different time recorders or stopwatches (i.e., start and stop times) for all of my timers and several other aspects. I drew my conclusions after looking at this information. All of my timers stop once the next timer begins and recording these show that they are all working at the times I imposed (with about 50~75 msecs of error).

So to answer your first question, the timer action event does not overwrite the current timer but stops it and begins a new one (all logged).

Based on that, it seems that when the timer in question (we will call timer “x”) begins to execute its action event, there is a 50 msec gap where no keydown input is recorded (i.e., the gap we see in the histogram).

(p.s., sorry I miswrote the previous post; I meant to say, when the timer event action starts, not when the timer begins to countdown to start its action event).

As far as I know, no key input has been blocked during this timeframe. In theory, the second that timer “y” or the timer before timer “x” starts its action event, the key down input should be available to be recorded until about 2000 msecs have passed.

i think a keydown event is only possible if the action method of the timer ends.
do you load a picture in this action event which cause a delay?
have also a look at
and maybe

I do load a picture in the action event of timer “x”. I did just run a debug on it to see if this is what is causing the delay and you are correct. Loading the picture does delay these timers.

This leads me to believe that, to solve this problem, I should preload each picture when I open the program?

Since you posted in “general”, it was not that easy to understand for which platform your question applied. From what you just told about preloading, it seems your app is Web. It is best to post in the relevant channel to get the best answers. BTW you should change channel accordingly.

Yes, indeed, better preload the pictures, or post them to a web space, and use the URL.

Dragging pictures in the project loads a lot slower, since pictures have to be sent to the browser at the time of display, which can take anywhere from 200ms to a full second.

Also, you want to optimize your pictures so they take a minimum of size.

This can help:


1 Like

Thank you very much!

In terms of where to post, this isn’t really a web platform as the pictures are loaded from jpg files within the computer but I see what you mean!

This was very helpful! I really appreciate it!

Another site which is great for PNG or JPG optimization is TinyPNG. You can try samples on their website to see the effect and compare the sizes and image quality. I typically see over an 80% reduction in filesize with no noticeable difference in the image.

I use their APIs in automated tasks. They also have plugins for Photoshop etc. Or you can just drop on site and they will convert.

HUGE help in page load times for graphic rich pages, especially over a slow or mobile connection.

1 Like

Anyway, to minimize load time, work on optimizing your pictures.

Another way to accelerate display is to use a page panel where you place the pictures. Then you flip the pages to go from one to the other.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.