I am trying to follow an example from a c# tutorial to trigger an event from the timer class when a certain amount of time has passed, however it doesn't seem to work.
Here is the code:
class Program
{
static void Main(string[] args)
{
System.Timers.Timer tmr = new System.Timers.Timer();
tmr.Elapsed += new ElapsedEventHandler(TimerTickHandler);
tmr.Interval = 1000;
tmr.Enabled = true;
Console.ReadKey();
}
public static void TimerTickHandler(object sender, ElapsedEventArgs e)
{
Console.Write("\rprinting: {0}", e.SignalTime.ToString());
}
}
I attached the TimerTickHandler on to the elapsed event and after each second it should print the time to the screen, but I am not getting any output.
Any clue as to where I am going wrong?
Thanks for any help.