DispatcherTimer in WPF
When you want to set a timer working with GUI, you always come across threading problem. In such scenario, .Net indeed makes programmers life easier. It only matters that you choose the right timer to use.
In Win Form, you need to use System.Windows.Forms.Timer.
In WPF, the one is System.Windows.Threading.DispatcherTimer.
Here is a simple sample code for DispatcherTimer.
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(someInterval);
timer.Tick += new EventHandler(someEventHandler);
timer.Start();
}
{
private void someEventHandler(Object sender, EventArgs args)
{
some operations
//if you want this event handler executed for just once
// DispatcherTimer thisTimer = (DispatcherTimer)sender;
// thisTimer.Stop();
}
P.S.
For general purpose, you can use System.Threading.Timer.
For server-based purpose, System.Timers.Timer can be the right choice.
hi hi, thks for your content …
Dai Hoang said this on February 22, 2008 at 2:46 am |
Thanks you for sharing your experience. I want to refesh textbox.text every seconds from someEventHandler, but the value does not displayed in texttox.
Do I need to refresh textbox or set waiting time?
and how? Thanks you
palmBeach said this on August 14, 2008 at 11:23 am |
Thanks a Ton.
Abhinandan said this on February 4, 2009 at 8:22 am |
Thanks a million.
Mohammad said this on May 4, 2009 at 5:12 pm |
muchas gracias por el tip
Luis Roberto Serrano said this on July 15, 2009 at 10:32 am |
I could not read the article proper;y due to the darkness and color combination of the template I wish I could read that Bu thave no time to give strain while other readable articles are there.
Meetu said this on September 15, 2009 at 8:25 am |
Thanks
Ozon said this on May 1, 2010 at 5:35 am |
Check this:
http://codex.wordpress.org/Writing_Code_in_Your_Posts
William said this on June 24, 2010 at 6:08 am |
Great article, thanks.
Eric Layne said this on July 21, 2010 at 5:59 pm |
NICE PASTE AND COPY DUMBASS
I GUESS IF YOU WANT TO READ CRAPOLA
READ WHAT THIS SOB AUTHOR POSTS
ROFL
JACK ASS said this on November 26, 2010 at 3:42 pm |
Just what I needed to see. Thanks.
Joe C said this on October 20, 2011 at 8:55 am |
[…] https://wangmo.wordpress.com/2007/09/07/dispatchertimer-in-wpf/ […]
DispatcherTimer WPF UI | Consistent Multiverse said this on January 14, 2012 at 8:51 am |
L’évent tick n’est pas précis sur cette page
Moooua said this on September 14, 2013 at 4:30 am |
sadasdasd
as said this on May 30, 2014 at 6:14 am |