em-timers | helper methods for timers in EventMachine
kandi X-RAY | em-timers Summary
kandi X-RAY | em-timers Summary
helper methods for timers in EventMachine.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of em-timers
em-timers Key Features
em-timers Examples and Code Snippets
Community Discussions
Trending Discussions on em-timers
QUESTION
I'm using System.Timers.Timer to backup my SQL Server Express Database once a day. It seems to work fine, most of the time. Occasionally, the ElapsedEventHandler gets called multiple times at 1 or 4 minute intervals. It should just be hit once a day. I have AutoReset as false and I call Start at the end of the ElapsedEventHandler. Also, possibly relevant is that I do recalculate the interval so that the timer always goes off as close to 1 am. as possible. The backing up of the database can take a few minutes, and if I didn't change the interval, the time might drift unacceptably. I mention this because these links suggest there might be a problem with resetting the interval:
See in particular the answers by Hans Passant
However, I don't see how I can avoid resetting the interval. Also, I looked into the code for System.Timers.Timer. It didn't seem like just resetting the interval would Start the timer again. I'm not opposed to using a different timer (System.Threading.Timer?) but I'd like to know what is going on first.
I've pasted all the code below. I would think the truly relevant part is the method: DatabaseBackupTimerOnElapsed
Finally, I'll mention that the program is sometimes stopped and restarted (if there are uncaught exceptions in other parts of the code). I would assume though that all timers are killed at the point of exiting the program even if Dispose is not called? That is Timers don't live on in the operating system?
EDIT I was requested to put down a small, complete, verifiable example. I do so here. I've kept the full example as someone might claim (quite correctly!) that I took out an important detail. I've run this code and have NOT seen the problem but then, it only happens very occasionally with the original code.
...ANSWER
Answered 2017-Jul-18 at 19:03I think the solution is overly complicated.
- The timer interval will fire the Elapsed event independent of when the fact that a previous run had finished or not, unless you explicitly stop the timer during the event. This should not be necessary. You could simply keep track of whether you are running or not when you enter the method.
Set the interval to 59999. This is a millisecond short of a minute. Then at entry in the event handler check if the current hour and minute correspond to the time when you want to backup.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install em-timers
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page