Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP7 Invalid cross-thread access - ScheduledTaskAgent

In WP7 app I am calling some code to update a live tile from the onInvoke method on the ScheduledAgent class.

Getting an invalid cross-thread error.

The line it is failing on is

var fontForeground = new SolidColorBrush(Colors.White);

I understand that there are limitations ans API's that I cannot call from within this background task, but I am only trying to setup some stuff to generate my own image to display on the Live tile.

Is there something obvious I am doing wrong here.

  • thanks

Update...

I have discovered this question

How can I render text on a WriteableBitmap on a background thread, in Windows Phone 7?

It is the same issue that I have and whilst there is some good dialogue on here it doesn't appear that there is an easy way to get around this?

like image 647
Peter Avatar asked Sep 15 '11 08:09

Peter


1 Answers

Use the Dispatcher to execute the code on the UI thread instead on a background thread:

Deployment.Current.Dispatcher.BeginInvoke(()=>
    { 
         fontForeground  = new SolidColorBrush(Colors.White);
         ...        
   });
like image 153
thumbmunkeys Avatar answered Oct 23 '22 09:10

thumbmunkeys