Timer in service

wl

Well-Known Member
Licensed User
Longtime User
Hello,

This post is related to my previous recent posts but contains a specific question so I thought it might be a good idea to start a new one.

I have a service (that I started in the foreground) that opens a TCP connection. I also start a timer so that after 5 minutes the connection sends a message and I start another one after 6 minutes to see whether, meanwhile, I received an answer. If not: I restart the service after 5 seconds.

It seems that the timertick in the service is not functioning well: I am not reaching this code every 5 minutes (a few times at the most).

Am I doing something wrong ?

Thanks !
 

thedesolatesoul

Expert
Licensed User
Longtime User
It is not so simple to say.
Are you saying that the timer does not fire at the correct time, or does it not fire at all?
Also, what is the service doing in the meanwhile?

I do not know the exact terminology, but try to visual this:
The thing is, all of these 3 asynchronous runnables (two timers and the service) will run on the same thread. Since timers are message based, the could be queued up while your main thread is doing something else. In that case it will fire quite late, but maybe the message times-out (speculating).
 
Upvote 0

timwil

Active Member
Licensed User
Longtime User
Instead of a timer you can force the service to restart in ??? minutes if you want with:

B4X:
StartServiceAt("",DateTime.Now + 10000,False)

this will start the service again in 10 seconds - and I think this is more accurate than the timer would be
 
Last edited:
Upvote 0
Top