You should never try to use
System.Windows.Forms.Timer
with WPF, and almost never even with Forms. The accuracy of this timer is prohibitively bad for most applications. There are (at least) three more timer types you can use:
http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx[
^].
Another option is using a separate thread with loop and
System.Threading.Thread.Sleep
, which I think is the easiest and most straightforward.
Now, as a timer event is not guaranteed to invoke in your UI thread, you generally need to invoke any method using the UI methods/properties on the UI thread, using the Dispatcher. You don't need (and cannot) do it with
System.Windows.Threading.DispatcherTimer
, but if you use a separate thread or other timer types, you need to use the dispatcher.
Please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
—SA