Android Question timer interval?

Michael Gasperi

Member
Licensed User
Longtime User
If a timer interval is 10ms and the code in the tick takes 5ms, does the timer event happen every 10ms or every 15ms?
 

DonManfred

Expert
Licensed User
Longtime User
Thanks. Now what happens if the code takes longer, say 15ms? Does the rate become 15ms?

As i already stated i would suggest

B4X:
sub timer_tick
  timer.enable = false ' Stop timer
  ' do your stuff here
  timer.enable = true  ' restart timer
end sub
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Sorry to hijack the question but it is also about timers.

What is the best for a long delay : have the timer internal for example datetime.TicksPerHour or store the targeted time and check regularly if this target is reached ?
Many thanks
 
Upvote 0

Michael Gasperi

Member
Licensed User
Longtime User
Thanks again for your help.

DonManfred, I don't think the enable toggle is necessary since the task will not try to restart again till it is done.

I tested the timing variation using DateTime.Now and found the following:
Timers greater than about 20ms will "on average" give you the interval time you want.
However, the time interval you get for a given tick can vary about -20ms to +35ms off this average.
A really short timer interval, like 10ms, averages 17ms and can be as short as essentially 0ms and as long as 45ms.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…