I have a question about using System.Timers.Timer in my .NET applications.
I have three different events, each of which fires every second, and the other fires every minute, and the last fires every half hour.
Is it better, in terms of performance, to have one timer or three?
The way to do this with a single timer is to check ElapsedEventArgs ' SignalTime and compare it with the previously measured time. Of course, this does not work if you changed the DateTime, but that is not a problem. Basically, every second when it passes, I check if a minute or half an hour has passed ...
My concern is that using 3 timers creates too much overhead. Am I mistaken and should I use 3 for simplicity and clarity, or is one timer enough?
code:
private void TimerEverySecondElapsed(object sender, ElapsedEventArgs e) { timerEverySecond.Enabled = false; OnTimerElapsed(TimerType.EverySecond);
minuteSpan and semiHourSpan are readonly TimeSpans.
source share