RSS

Tag Archives: Fix Unhandled Error in Silverlight 2 Application Invalid cross-thread access error

Invalid cross-thread access in silverlight


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();
}
);

 

 

 

 
Leave a comment

Posted by on February 24, 2012 in Silverlight

 

Tags: , , , , , , ,