0

When to use which timer, daily task ?

Can some explain me more about timers in c#. I have seen 3 different timers, but do not know which one I should use. System.Threading.Timer System.Timers.Timer System.Windows.Threading.DispatcherTimer I have a task in a c# / wpf program, which needs to run once a day. It is a copying task so it has nothing to do with UI. Currently I have a timer ( System.Timers.Timer) , which has a interval of 3600 000 ms (1 Hour). In the Elapsed_event, I test if DataTime.Now.Hour == 5 If it is 5, I perform the copying task. But I am not sure this is the best way and best timer to do this.

25th Mar 2018, 6:59 PM
sneeze
sneeze - avatar
3 Answers
+ 4
To know the difference between this three types recommend you tocheck this: This article offers a fairly comprehensive explanation: https://web.archive.org/web/20150329101415/https://msdn.microsoft.com/en-us/magazine/cc164015.aspx The specific difference appears to be that System.Timers.Timer is geared towards multithreaded applications and is therefore thread-safe via its SynchronizationObject property, whereas System.Threading.Timer is ironically not thread-safe out-of-the-box.
25th Mar 2018, 7:04 PM
Baraa AB
Baraa AB - avatar
+ 3
Welcome bro.. glad to hear that.. good luck šŸ’™
26th Mar 2018, 7:37 PM
Baraa AB
Baraa AB - avatar
+ 1
Thanks. It is really good article.
26th Mar 2018, 7:35 PM
sneeze
sneeze - avatar