Geeks With Blogs
Phubar Baz Musings of an HTML5 Programmer

I was trying to port an old app from c# 2.0 to WPF in 4.0. In one place I was using a Timer to handle filtering of a list from a text box. This kept the list from constantly being updated while the user is typing because it was getting data from the database. I set a 250 millisecond interval so whenever they paused it would update the list.

The Timer class apparently got completely redefined in .Net 4.0. It used to have a Tick event, but this was changed to Ellapsed. Also I found out that it didn't work very well with the UI thread. When I tried to access the text field in the UI I would get a concurrency exception.

Finally I found a new class called DispatchTimer under the System.Windows.Threading namespace that does exactly what the old Timer class used to do. It allows you to do timer events that interact with the UI.

Posted on Friday, January 13, 2012 9:41 AM | Back to top


Comments on this post: C# DispatchTimer

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © PhubarBaz | Powered by: GeeksWithBlogs.net