views:

43

answers:

1

I have read that we can not access anything in the main UI thread in Silverlight application from other worker threads.

So why it is possible to access an object of class System.Windows.Threading.Dispatcher which is associated with the main UI thread from other worker threads when we want to delegate some work to be done on the User Interface ?

public partial class DispatcherExample : UserControl
{
  public void AnyFunctionExecutingInSomeOtherThread()
  {
    this.Dispatcher.BeginInvoke(SomeDelegate);
  }
}
+3  A: 

A Dispatcher instance can be accessed from any thread because it does not have thread affinity. If it did have thread affinity, it would essentially be useless because its main reason for being is to dispatch messages onto the correct thread from any thread.

HTH,
Kent

Kent Boogaart