Created
October 27, 2014 10:12
-
-
Save kristofferremback/d6b8b7fcce775108dff7 to your computer and use it in GitHub Desktop.
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
// Declare an object called timer and the integer. | |
private static Timer timer; | |
private static int i = 0; | |
static void Main(string[] args) | |
{ | |
// Set the timer to be a new Timer with an interval of 2 seconds. | |
timer = new Timer(2000); | |
// Everytime that interval has been reached, fire off this event. | |
timer.Elapsed += OnTimedEvent; | |
// The timer is now enabled and will start printing stuff. | |
timer.Enabled = true; | |
// Print the "first" value | |
Console.Write("{0}", i); | |
// This one waits for user input, as long as none is given, the progam will go on forever. | |
// (I.E. a key is not pressed) | |
Console.ReadKey(); | |
// Will just flash by as the program will be closing. | |
Console.WriteLine("Terminating the application..."); | |
} | |
private static void OnTimedEvent(Object source, ElapsedEventArgs e) | |
{ | |
// Increment the integer | |
i++; | |
// \r makes the console go back all the way on the row, | |
// and {0} prints out whatever the first value is on the other side of the comma (which in this case is the integer i). | |
Console.Write("\r{0}", i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment