I know that c# allows to use a timer using:
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 1000/60;
timer.Tick += new EventHandler(TimerEventProcessor);
timer.Start();
private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
//Do something
}
But, I have seen in this YouTube tutorial that instead of using Timer
they created a thread that implements a timer of its own:
var task = new Task(Run());
task.start();
protected void run ()
{
while (true)
{
Thread.sleep(1000/60);
//Do something
}
}
Are there any benefits to using the second way over the simpler Timer
?