Created
May 17, 2013 05:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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