The way I do this is a timer.
Start the server timer, check it hour / minute every 60 seconds.
If this is the correct hour / minute, start the process.
This is actually abstracted into the base class, which I call OnceADayRunner.
Let me clear the code a bit and I will post it here.
private void OnceADayRunnerTimer_Elapsed(object sender, ElapsedEventArgs e) { using (NDC.Push(GetType().Name)) { try { log.DebugFormat("Checking if it time to process at: {0}", e.SignalTime); log.DebugFormat("IsTestMode: {0}", IsTestMode); if ((e.SignalTime.Minute == MinuteToCheck && e.SignalTime.Hour == HourToCheck) || IsTestMode) { log.InfoFormat("Processing at: Hour = {0} - Minute = {1}", e.SignalTime.Hour, e.SignalTime.Minute); OnceADayTimer.Enabled = false; OnceADayMethod(); OnceADayTimer.Enabled = true; IsTestMode = false; } else { log.DebugFormat("Not correct time at: Hour = {0} - Minute = {1}", e.SignalTime.Hour, e.SignalTime.Minute); } } catch (Exception ex) { OnceADayTimer.Enabled = true; log.Error(ex.ToString()); } OnceADayTimer.Start(); } }
The beef method is in the e.SignalTime.Minute / Hour check.
There are hooks for testing, etc., but thatβs what your past timer might look like so that it all works.
CubanX 02 Feb '09 at 15:26 2009-02-02 15:26
source share