I want to use a timer in my simple .NET application written in C#. The only one I can find is the Windows.Forms.Timer class. I don't want to reference this namespace just for my console application.
Is there a C# timer (or timer like) class for use in console applications?
The Timer class in C# represents a Timer control that executes a code block at a specified interval of time repeatedly. For example, backing up a folder every 10 minutes, or writing to a log file every second. The method that needs to be executed is placed inside the event of the timer.
The timer icon, called timer1, appears in a space below the form. Select the Timer1 icon to select the timer. In the Properties window, select the Properties button to view properties. Set the Interval property to 750, which is 750 milliseconds.
Remarks. The Timer component is a server-based timer that raises an Elapsed event in your application after the number of milliseconds in the Interval property has elapsed. You can configure the Timer object to raise the event just once or repeatedly using the AutoReset property.
System.Timers.Timer
And as MagicKat says:
System.Threading.Timer
You can see the differences here: http://intellitect.com/system-windows-forms-timer-vs-system-threading-timer-vs-system-timers-timer/
And you can see MSDN examples here:
http://msdn.microsoft.com/en-us/library/system.timers.timer(VS.80).aspx
And here:
http://msdn.microsoft.com/en-us/library/system.threading.timer(VS.80).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With