WP7无效的跨线程访问-ScheduledTaskAgent [英] WP7 Invalid cross-thread access - ScheduledTaskAgent
问题描述
在WP7应用程序中,我正在调用一些代码来从ScheduledAgent类的onInvoke方法更新实时磁贴.
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.
它失败的行是
var fontForeground = new SolidColorBrush(Colors.White);
我知道在这个后台任务中无法调用ans API,但我仅尝试设置一些东西来生成自己的图像以显示在Live磁贴上.
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.
- 谢谢
更新...
我发现了这个问题
如何在Windows Phone 7中在后台线程的WriteableBitmap上呈现文本?
这是我遇到的同样的问题,尽管这里有一些很好的对话,但似乎没有一个简单的方法可以解决此问题?
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?
推荐答案
使用Dispatcher
在UI线程上而不是在后台线程上执行代码:
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);
...
});
这篇关于WP7无效的跨线程访问-ScheduledTaskAgent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!