I have a service running that monitors other services and restarts them when needed. After starting I check if the start is successful. Works fine.
But today I added a service that apparently takes a bit more time to start so my check if the start was successful comes to early. So I need a kind of delay between those two lines. I don’t want to use the SLEEP() command in the case. As far as I know that would delay the whole application which is not good it will also confuse the timer event which has to fire every three minutes.
Is there some other way I can get a delay between to commands instead of using SLEEP()? I guess a delay of 300ms will be sufficient.
OK that is good to know, thanks. Unfortunate that doesn’t help in this case because this application has just one thread. The checking and starting is done in a UserEvent on the main procedure.
On the newsgroup I got a pragmatic solution: Why not wait for the next timed event to check if the restart worked? For a non-essential service that might be ok.
use the Timer:event. Set Prop:timer to a shorter interval to start and then increase it after your services have started. You may want to save the FirstTime in the Event:OpenWindow. I believe the first timer event fires right after the open window and then goes the specified interval. Although I may be wrong about that…
In my experience not. It take three minutes to fire the first check which is the interval I set my timer to. Maybe it makes a difference that my application is running as a service, not sure didn’t test.
Setting the PROP:Timer to a shorter interval for that slow starting service is something I don’t prefer. A continuous checking of the more important services is more important to me. I choose a more pragmatic solution, just wait for the next cycle to see if the restart works because most of the time that will be the case.
Instead of 3 minutes you could set your Timer to 30 to 60 seconds always.
Then you measure time elapsed as Clock() - Last Time Processed My 3m Thing. If it’s been 18,000 H Seconds you process your 3 minute thing. This allows multiple time intervals to be tracked.
There are a few details to deal with like at Midnight the Clock() resets back to zero. Simple code needs to check IF Clock() < Last Process to see if there was a Midnight.
I would use the API GetTickCount as a tiny bit more efficient than Clarion’s Clock.
Well this is just an example that someone (me in this case ) can really get blindfolded when running into a problem. I never thought about changing the interval time.
Interesting, would the be noticeable when running a small task every one minute?
The purpose of GetTickCount is to let you measure intervals of time. It provides a common clock source so that multiple components can coordinate their actions. It also allows you to retrieve the tick count at one point, then retrieve the tick count at another point, subtract them, and conclude how much time has elapsed between those two points.
When the System Timer changes Windows stores the Tick Count so it is very fast and simple to get versus asking the Clock the current time.