by Bobbi Perreault
17. April 2008 22:21
Share on Facebook
Just yesterday when I was working on a WPF application, I was searching for a simple introduction to the new way to do threading. I had no luck with that, there were plenty of tutorials, just none that I could skim through to pick up the light details I needed. And time is always so short!
This morning, though, I had in my RSS feed just what I needed. Here it is: http://wilcoding.xs4all.nl/Wilco/News/threading-in-silverlight.aspx
Threading in Silverlight
Posted at Thu, 17 Apr 2008 00:09:06 GMT by Wilco Bauwer
Silverlight 2 brings support for threading to the browser. You can either directly start new threads using System.Threading.Thread and System.Threading.ThreadPool, or you can use the higher-level (and recommended) System.ComponentModel.BackgroundWorker type. The latter encapsulates the concept of executing work in the background (using a thread from the thread-pool) and updating the UI based on progress and/or completion of that work, which means that you can safely update the UI from the related events.
WPF version:
CallStatDisplay.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(delegate { myTextBlock.Text = "Updated from a non-UI thread."; }));
Actually WPF uses dispatcher threading model which means the ui elements in WPF are dispatcher affinitized, you can only perform operations on UI elements in the dispatcher which creates them. since dispatcher is affinitized with a specific STA thread, so WPF still uses the single threaded model which Windows Forms employ, for more info on WPF's threading model please refer to:
http://msdn2.microsoft.com/en-us/library/ms741870.aspx