System.Timers.Timer and slick way to skip processing at configurable times

  • Thread starter Thread starter josh
  • Start date Start date
J

josh

Hello,

I have written a Windows Service that checks ODBC connectivity to a
legacy ODBC source on a specified interval (15 minutes for example).
If unexpected downtime are encountered, I log an event to the event
viewer and email IT of this unexpected downtime. The settings for the
windows service are configured in the app.config but they could just as
easily be set in the registry.

I am looking for advise on how enable an easy way to configure known
"periods of downtime" where the Elapsed event can check to see if the
service is about to fire the EventHandler during one of these
configured "downtimes" and skip firing the event until it checks again
for the next interval.

For example, if the service runs all the time, and I know that our ODBC
source is down for 30 minutes starting at 10:00 AM, I want to prevent
the EventHandler of the Elapsed event from running it's test and
logging/sending unnecessary error messages.

I'd like to be able to add 0 to many downtimes to the service to
prevent these known downtime messages from being logged/sent.

I've looked at 2 different methods so far but figured there must be a
more elegant way:

1) Add appSettings "Downtime1...DowntimeN" with corresponding
"TimeSpans1...n"
2) Adding a custom IConfigurationSectionHandler to handle this, but I'm
a bit fuzzy on how to accomplish this.

Here are some examples of possible downtimes:

10:00 AM - 10:30 AM (down for quick morning backup)
9:00 PM - 3:00 AM (down for night processing)
etc.

Any advise is appreciated.

Thanks,

Josh Blair
 
I think this should be in a data source that is easy for someone to update,
and easy for the application to read. An XML file, an access database, etc
 
Back
Top