developers.de
daenet's .NET Community

UnauthorizedAccessException: Invalid cross-thread access.

Damir Dobric Posts

 

Damir@Phone    



My upcoming sessions:

AppFabric Applications at
NRW Conf 2011
09.Sept.2011 Wuppertal

HTML5 widgets in WP7+
Monodroid
Mobility Day
21.Sept.2011 - Zagreb

AppFabric and WCF sessions at
Advanced Developer Conference
26.-27. Oktober 2011 in Frankenthal

AppFabric Applications, queues, topics and more at
Prio Conference
02. - 03. November 2011 in Meistersingerhalle Nürnberg

AppFabric Applications deep dive hosted by
.NET User Group Frankfurt
17.Nov.2011 18.30-22.30 Microsoft - Bad Homburg 

 

 

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!!!

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
daenet GmbH