WP7无效的跨线程访问

编程入门 行业动态 更新时间:2024-10-22 16:38:40
本文介绍了WP7无效的跨线程访问-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无效的跨线程访问

本文发布于:2023-11-27 03:14:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!