I would like to implement some timers into my application.
My goal is to provide an easy way to execute some function every x seconds/minutes so I thought about implementing a 1 sec, 5 sec and 15 seconds timer.
The first thing i would like to update every 1 second is the built in clock (don’t know if there is any other solution in c#, used this method in c++)
Another use would be e.g. a sync function etc. which shall be executed every xx seconds.
My question is if there are any useful tutorials on this topic? It is the first time that I would like to implement such an timer system into one of my applications and I do not know if there are any things I have to keep in mind.
Thank you in advance for any answer 🙂
There are various types of Timer classes you can use.
In WPF, if this is for updating something user interface related, you would typically use a
DispatcherTimer.You could also use a
System.Timers.TimerorSystem.Threading.Timer, but realize that this will fire on a background thread, and not on the main user interface thread. This is often beneficial (you don’t wait or block your UI if there is “work” happening in the Timer’sTickevent or callback), but you also have to remember to marshal anything user interface related back to the UI thread.