The expired timer event fires twice when the program starts. The sole purpose of the Expired event handler is the Primary Method. Is there something I'm doing wrong?
//class level clock public static System.Timers.Timer Clock; static void Main(string[] args) { Clock = new System.Timers.Timer(); Clock.Elapsed += new ElapsedEventHandler(Clock_Elapsed); Clock.AutoReset = false; Clock.Interval = timerInterval; //this needs to be in milliseconds! Clock.Enabled = true; //run infinite loop until q is pressed while (Console.Read() != 'q') {} } static void Clock_Elapsed(object sender, ElapsedEventArgs e) { Clock.Stop(); //do some stuff Clock.Start(); }
UPDATE:
The car grill provided by @ fparadis2 recorded firing twice. The main problem was that my timer interval was set to 30 milliseconds instead of 30,000 milliseconds (30 seconds) so that the event would be double.
source share