Timer in WPF
In Windows Form time, there is a component for Timer. But in WPF, there is not such things. So, what thing we can do, when we need to execute a piece of code periodically. We can use the timers under System.Timers. But please do not use System.Timers.Timer, because it triggered, it will execute the code in a new thread. If you try to access any controls in WPF Windows, the system will throw an exception. I like to use System.Windows.Threading.DispatcherTimer in WPF, because that is very similar with the Timer in Windows Timer.
There are the example code:
Code
DispatcherTimer sysTimer = new DispatcherTimer(); | |
sysTimer.IsEnabled = true; | |
sysTimer.Interval = new TimeSpan(0, 0, 1); | |
sysTimer.Tick += new EventHandler(sysTimer_Tick); |
To find more about this, please download the example project, AdvGenStopWatch.
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Feedback awaiting moderation
This post has 44 feedbacks awaiting moderation...
Form is loading...