在WP7应用程序中,我调用了一些代码来从ScheduledAgent类的onInvoke方法更新实时磁贴。
获得无效的跨线程错误。
它失败的线是
var fontForeground = new SolidColorBrush(Colors.White);
据我所知,我无法在此后台任务中调用API,但我只是尝试设置一些内容来生成我自己的图像以显示在Live磁贴上。
有什么显而易见的我在这里做错了。
更新......
我发现了这个问题
How can I render text on a WriteableBitmap on a background thread, in Windows Phone 7?
这是我遇到的同样的问题,虽然这里有一些很好的对话但似乎没有一种简单的方法来解决这个问题?
答案 0 :(得分:36)
使用Dispatcher
在后台线程上执行UI线程上的代码:
Deployment.Current.Dispatcher.BeginInvoke(()=>
{
fontForeground = new SolidColorBrush(Colors.White);
...
});