I am trying to initialize a timer that calls a method every second. I need to initialize it from within another event handler.
I wrote this code but it still gives me a compile error. They, both the initialization and the event handler are in the same class.
private void Controllel_Opened(object sender, EventArgs e)
{
System.Timers.Timer myTimer = new System.Timers.Timer();
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(DisplayTimeEvent);
myTimer.Interval = 1000; // 1000 ms is one second
myTimer.Start();
}
public static void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
// code here will run every second
}
Any suggestions?