Reputation: 11844
i am using a timer elapsed event for automatic database backup, the timer will check for every 5 seconds, once the current time equals to the time given in app.config the database backup will happen. I want to make the timer not to check again immediately when the backup happen. can anyone help me this.
Upvotes: 0
Views: 473
Reputation: 941227
once the current time equals to the time given in app.config the database backup will happen
That has a knack of not working. The config could say 10:05:00, the timer elapses at 10:04:58 and 10:05:03. There's no point in firing that timer every 5 seconds. Just fire it once. When the backup is due. If the user changes the due time, stop and re-start the timer to use the altered TimeSpan.
Upvotes: 1
Reputation: 39697
If using the Sytem.Timers.Timer object you would do
timer.Stop()
as the first line in your elapsed event, then do the backup, and do
timer.Start()
at the end to restart the event.
If using System.Threading.Timer use
timer.Change(Timeout.Infinite, Timeout.Infinite)
and then restart it with the appropriate values.
Upvotes: 1
Reputation: 11734
Pause the timer when the backup is running.
Otherwise.. (Not sure what DBS you are using) why not use SQL Server Agent Jobs?
Upvotes: 0