System.Timers.Timer running certain hours of the day

  • Thread starter Thread starter Bob Day
  • Start date Start date
B

Bob Day

Using VS 2003, VB Net, MSDE...

Is there a way to cause a System.Timers.Timer to only execute between 7AM
and 10PM and essentially go to sleep otherwise?

I don't see any.

Please advise.

Thanks!
Bob
 
.. . .
Is there a way to cause a System.Timers.Timer to only execute
between 7AM and 10PM and essentially go to sleep otherwise?

No. If you stopped it at 10pm, what would start it up again at 7am?
- unless you had another Timer to do that ;-)

If having the Timer running /all/ the time isn't too much of an overhead,
you could always teach the *_Elapsed routine how to tell the time ...

Sub tmrPoll_Elapsed( ...
Select Case Now().ToString( "hh:mm" )
Case "07:00" To "22:00"
' Do Something Useful
End Select
End Sub

HTH,
Phill W.
 
Not sure if it will help, but the System.Threading.Timer allows you to
specify a delay before the first tick.
 
Bob,
Have you considered a variation of Phill's suggestion?

At 10PM change the duration of your timer such that it fires at 7AM. At 7AM
change the duration so that it fires on your normal frequency.

Alternatively you could use a System.Threading.Timer to fire at 10PM to
disable the System.Timers.Timer, and to fire at 7AM to enable the
System.Timers.Timer. If you use Threading.Timer objects you could set them
to a 24 hour duration & let them be...

Remember that System.Threading.Timer takes a TimeSpan, so you would need to
find the timespan till 10PM or 7AM for the start...

Hope this helps
Jay
 
Back
Top