How do timers work in .NET?
You should use System.Timers.Timer
Add a method that will handle the Elapsed
event and execute the code you want. In your case:
System.Timers.Timer _timer = new System.Timers.Timer();_timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);_timer.Interval = 60000;_timer.Enabled = true;private static void OnTimedEvent(object source, ElapsedEventArgs e){ // add your code here}
Here is a good post regarding the difference between the two Timers
:
You need to use Timer
class.
There are multiple built-in timers ( System.Timers.Timer
, System.Threading.Timer
, System.Windows.Forms.Timer
,System.Windows.Threading.DispatcherTimer
) and it depends on the requirement which timer to use.
Read this answer to get and idea of where which timer should be used.
Following is an interesting read.
Comparing the Timer Classes in the .NET Framework Class Library