One framework to rule us all…
.NET Framework 4.0, C#, WPF

Using the .NET 4 Task class in WPF

Here’s a quick example on how to implement an asynchronous call in WPF using the System.Threading.Tasks.Task class. Keep in mind that underneath, the call will still end up in a thread pool, as opposed to a ThreadPool approach.

The trick is to use TaskScheduler.FromCurrentSynchronizationContext() to make sure we can work in the UI Thread. ContinueWith sets up a follow-up call to do some final work and that’s it.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Leave a Reply