When working with WCF DataServices in Silverlight 3 your callback methods have been executed on the UI-thread.
Here is one example which works in Silverlight 3.0.
private void onOperationCompleted(IAsyncResult result)
{
DataServiceQuery<View> ctx = result.AsyncState as DataServiceQuery< View >;
ViewData.Result = ctx.EndExecute(result);
}
When this is migrated to Silverlight 4.0 following exception is thrown:
The solution for this looks like:
private void onOperationCompleted(IAsyncResult result)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
DataServiceQuery<View> ctx = result.AsyncState as DataServiceQuery<View>;
IEnumerable< View > stations = ctx.EndExecute(result);
ViewData.Result = ctx.EndExecute(result);
});
}
Posted
Apr 22 2010, 04:36 PM
by
Damir Dobric