If you have used multiple threads or just timers in your applications, you probably know that if you have to update any user interface, control you should not do it from any other thread but from the one that the control was created from. That is why if your application uses multiple threads, you always have to be aware of what thread you are in.
In Silverlight invoking a piece of code in the user interface thread can be achieved by using the BeginInvoke method of the System.Windows.Threading.Dispatcher class. However you cannot create an instance of the Dispatcher class but you can use the one each object that derives from System.Windows.DependencyObject exposes through its Dispatcher property.
Check out the code snippet bellow:
C#
// Method executed in some other non UI thread!
private void OtherThreadMethod()
{
//Invoke the method that should change the control in the UI thread
this.Dispatcher.BeginInvoke( UIThreadMethod );
}
private void UIThreadMethod()
{
//Perform the change of the control
this.Cursor = Cursors.Wait;
}
That's it!