Android Question How to fire a timer before its interval

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Hi,
I have a service with a timer of 10 seconds.
The timer fires a routine which reads some data from the web
I need to tell the service to read that data "now" no mater what the timer is set on.
Any Idea?
Thanks
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
and how do I call it from inside the same service? I can check a main variable in the service timer but haw does the timer know I need to call its own _tock sub?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
You can just call the sub like you would any other sub. But personally I think it's better to move all the code out of the tick event and into a new subroutine. Then you can call this sub from the tick event or from anywhere else in your code.
It really makes no difference but I just like to have event driven subs fired by the events and not manually called in the code, in my opinion it makes the code easier to follow.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
B4X:
Sub TimerBruteForce
    tmTimer.Enablled = False
    tmTimer.Enablled = True
End Sub
__________________________________________

Sub btnButton_Click
   TimerBruteForce
End Sub
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
The Sub I need to call is in a service which fires it with a timer.
What happen if I call the service sub from another module "at the same time" as it was called by the service itself?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
It is still running on the main thread and so it can only occur one after the other. If your not wanting to repeat the process in the Tick event just use a Process Gloabl variable to set whether your function has been run or not.
 
Upvote 0
Top