[Gambas-user] Best method to trigger event at midnight?

Tobias Boege taboege at ...626...
Sat Mar 23 20:20:28 CET 2013


On Sat, 23 Mar 2013, Beno?t Minisini wrote:
> Le 23/03/2013 19:43, dr.diesel a ?crit :
> > I'm looking to trigger an event at midnight, any suggestions on the best
> > method to ensure the time is not missed?
> >
> > My application reads/writes a DB, launches websites and reads heavily on the
> > COM port.  I'm afraid that if I simply look for the date/time to be 00:00
> > I'll miss the time while some other event is happening.  Do I need to just
> > carefully code this or is there some other method I'm not seeing?
> >
> > Many thanks
> > Andy
> >
> 
> Check the time with two timers.
> 
> For example, the first timer will be raised for example each hour. And 
> when it is past 23:00, start another timer with a more precise 
> resolution to check when midnight is reached.
> 
> You can use more timers. It depends on which precision you need.
> 
> But beware that there is only one thread in Gambas, so a too long event 
> handler prevents other events to be raised.
> 
> Regards,

Isn't it simpler to calculate the time delta until midnight and then,
depending on what the application otherwise does:

a) it's otherwise idle: Wait iDelay (or even Sleep iDelay)
b) it has something to do: arm a Timer with iDelay to expire once

This would require only one Timer and less overall effort. Any
inconvenience I missed with this approach?

Regards,
Tobi




More information about the User mailing list