UnauthorizedAccessException: Invalid cross-thread access.

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

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:

image

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
Filed under: ,

Comments

Klin wrote re: UnauthorizedAccessException: Invalid cross-thread access.
on 06-03-2010 8:56

Cool

it's works!!!

developers.de is a .Net Community Blog powered by daenet GmbH.