Showing posts with label Client Object Model. Show all posts
Showing posts with label Client Object Model. Show all posts

Wednesday, October 6, 2010

Accessing the UI thread in Silverlight

I’m creating a separate class where I want to move all related Client Object Model (COM) code.

In my case for the COM code to work it must update the UI thread. To accomplish this I had to move the reference from the main page, which was apparently passing through the Deployment object, to explicitly calling the Deployment object.

So in the case of the main page or I suspect any xmal pages code behind use this line of code in the ClientRequestSucceededEventHandler method:

this.Dispatcher.BeginInvoke(updateUI);


For separate classes to gain access to the UI thread use this line of code in the ClientRequestSucceededEventHandler method:

Deployment.Current.Dispatcher.BeginInvoke(updateUI);



Reference:
http://www.go4answers.com/Example/error-invalid-cross-thread-access-48335.aspx
Using Silverlight Object Model: http://msdn.microsoft.com/en-us/library/ee538971.aspx