RSS

Invalid cross-thread access in silverlight

24 Feb

Now when I receive DataServicesQuery.EndExecute and use this to pupulate a list that is bound to a usercontrol via a view model I get: “System.UnauthorizedAccessException: Invalid cross-thread access”

this error also heppend in silverlight application when you create user control or after fill list<myobj> and pass to griddate or radgridview( Telerick) control.

but here is suggests the following fix:

 

Dispatcher.BeginInvoke(
() =>{
CustomersGrid.ItemsSource = nwContext.EndExecute<Customers>(asResult).ToList();
}
);

 

Also use like………

 

You can change the code above so that the query executes on the UI thread by using the Deployment.Current.Dispatcher object.
e.g.:

Deployment.Current.Dispatcher.BeginInvoke(

() =>{
ICustomerModelInstance.GetCustomers();
}
);

 

 

 

Advertisements
 
Leave a comment

Posted by on February 24, 2012 in Silverlight

 

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: