Android Question Timer and thead

CurtisC

Member
Licensed User
Longtime User
Once again entering new territory. I am trying to provide 60 seconds as the duration of an event. While the 60 seconds is counting down other timers of different intervals will be starting and stopping. I have noticed that timers can be affected by other timers and I want to be as accurate and more importantly consistent for the 60 second count as possible.

Is a new thread my best course? And how do I include or start a timer in the new thread?

Or would using system time be more certain? Seconds are my only concern so continually reading system time and updating on the seconds I believe would work.
 

CurtisC

Member
Licensed User
Longtime User
You are correct I can not say the timer intervals are disrupted or delayed but whatever was to occur is disrupted or delayed or at least appears to be. I deal heavily with graphic files or more than likely graphic file load or movement would have been the actions of the timers. I could live with 60 seconds actually taking 61 seconds as long as each time it is 61 seconds, and just as vital is appearing to be consistent and trustworthy.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
I was curious as to what Timer trouble you were having because I've also noticed problems with Timer accuracy and reliability (mostly in B4J, though). I would occasionally see Timer events raised a second or two early or sometimes an entire interval late (resulting in two raisings happening one right after the other). I used a global variable to store the time of the last raising and checked that time during the next raising.

As for your using Timer in another Thread, I don't think that will work. The Timer's _Tick event will still be raised in the main Thread and the Timer's internal counting is already done asynchronously.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I can say, that in my experience, having multiple timers is problematic at best.

I have achieved better results (more consistent anyway) by having just one timer thread firing at the lowest interval resolution I need. In that one _Tick event, I then check individual "timer variables" to see what needs to happen (e.g. If DateTime.Now - TimerLong1 >= 60000 Then do event 1 stuff and set TimerLong1 = DateTime.Now when done).
 
Upvote 0

CurtisC

Member
Licensed User
Longtime User
Thank you for your knowledge and advice. Very helpful.

I have multiple timers each at different intervals. The 60 seconds will span over several cycles of the other timers so the other timers would be enabled and disabled several times. Jumping from one timer to another makes no sense so one common timer sounds like the best option. Then make the 60 second count down the priority and complete that action before addressing the other actions should keep the time accurate.
 
Upvote 0
Top