Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a timer class in C# that isn't in the Windows.Forms namespace?

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?

like image 804
MrDatabase Avatar asked Oct 03 '08 23:10

MrDatabase


People also ask

What is timer class in C#?

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.

How do I create a timer in Visual Studio?

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.

What is timer class in VB net?

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.


1 Answers

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

like image 95
albertein Avatar answered Oct 04 '22 01:10

albertein