Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

windows phone 7 - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...