Skip to content

Instantly share code, notes, and snippets.

@gorauskas
Created May 17, 2013 05:48
Show Gist options
  • Save gorauskas/5597183 to your computer and use it in GitHub Desktop.
Save gorauskas/5597183 to your computer and use it in GitHub Desktop.
Here is a cool trick to show a timer that updates in place in a console window.
using System;
using System.Timers;
namespace termtimer {
class MainClass {
public static void Main(string[] args) {
Timer t = new Timer();
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
t.Interval = 1000;
t.Start();
// break and exit when the user enters `Q`
while (Console.Read() != 'Q') { ; }
}
private static void t_Elapsed(object sender, ElapsedEventArgs eea) {
Console.Write("\r{0}", DateTime.Now);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment