+ 2

When to use which timer ?

I need a timer in wpf application. I found three timers, but do not know which one to use System.Threading.Timer System.Timers.Timer System.Windows.Threading.DispatcherTimer What is the difference between these  timers? When do you prefer a certain timer ? Which one do you use ?

21st Mar 2018, 1:37 PM
sneeze
sneeze - avatar
5 ответов
+ 11
Would you mind to elaborate on the usage of the timer in your application so we can help you to narrow down the choice? There are always more than one way to solve a problem in programming so getting into the specific definitely help to make better decision. 😉
21st Mar 2018, 2:49 PM
Zephyr Koo
Zephyr Koo - avatar
+ 8
Sorry for overlooking the post. It seems that the recommended way to do it is using System.Threading.Timer as it runs on a different thread and don't need to tie with the UI. I believe you can find good explanation on MSDN and some StackOverflow posts regarding the difference. 😉
26th Mar 2018, 3:15 AM
Zephyr Koo
Zephyr Koo - avatar
+ 2
Up Maybe my question got lost in the stack, I am still looking for the answer though. Can you answer my question or do I need to explain more ?
24th Mar 2018, 8:07 PM
sneeze
sneeze - avatar
0
Sure. I would like to know in which case I should use which one in general. They a look a like for me at the moment. To be specific. 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.
21st Mar 2018, 8:37 PM
sneeze
sneeze - avatar
0
Thanks.
26th Mar 2018, 7:36 PM
sneeze
sneeze - avatar