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 是我无法从这个后台任务中调用的,但我只是想设置一些东西来生成我自己的图像以显示在实时磁贴上.
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.
我在这里做错了什么.
- 谢谢
更新...
我发现了这个问题
如何在 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屋!