Android Question How to fire a timer before its interval

Discussion in 'Android Questions' started by Alberto Michelis, Jun 13, 2015.

  1. Alberto Michelis

    Alberto Michelis Active Member Licensed 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
     
  2. NJDude

    NJDude Expert Licensed User

    Just call the _Tick sub when you need it.
     
    LucaMs and Peter Simpson like this.
  3. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    and what if the timer calls it at the sema time?
     
    Beja likes this.
  4. Alberto Michelis

    Alberto Michelis Active Member Licensed 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?
     
  5. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
     
    Peter Simpson and LucaMs like this.
  6. Beja

    Beja Expert Licensed User

    Code:
    Sub TimerBruteForce
        tmTimer.Enablled = 
    False
        tmTimer.Enablled = 
    True
    End Sub
    __________________________________________

    Sub btnButton_Click
       TimerBruteForce
    End Sub
     
  7. Alberto Michelis

    Alberto Michelis Active Member Licensed 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?
     
  8. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
     
Loading...