本文介绍了在非UI线程上运行RIA服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试从非UI线程进行RIA服务调用.我通过打开新线程和后台工作者进行了调用,但是在这两种情况下,回调都在UI线程上运行.是否可以在调用者线程而不是UI上执行回调?谢谢I am trying to make RIA service calls from non UI thread.I made calls with opening new thread and with background workers, but for both cases callback is running on UI thread.Is it possible to execute callback on callers thread, not UI?Thanks推荐答案 tl; dr使用WCF将结果自己编组到UI线程 WCF RIA可以在UI线程上运行 WCF RIA设计为主要在UI线程上工作.这显然有很多优点和缺点;大多数情况下是不利的.我在查找有关此设计的权威文档时遇到了麻烦,但是,通过确定UI线程性可以回答有关此主题的大多数问题.WCF RIA was designed to work mostly on the UI thread. That obviously has many pros and cons; mostly cons in your case. I'm having trouble finding definitive documentation of this design, however, most questions on the topic are answered by affirming the UI threadedness. 这是WCF RIA质量检查小组成员表示用户界面的帖子仅线程处理. Andy French 描述了编组到UI线程的回调:Here is a post from a member of the WCF RIA QA team indicating UI-thread-only processing.Andy French describes the callbacks marshalling to the UI thread:如果使用WCF获取自己的数据,则可以在任何喜欢的线程上进行操作.调用完成后,您将必须编写(或借用)代码以更新UI线程上的UI,以避免跨线程异常.If you use WCF to get your own data, you can do it on any thread you like. When the calls complete, you will have to write (or borrow) the code to update the UI on the UI thread to avoid cross thread exceptions. IMO,WCF RIA的主要优点为简单的问题提供了简单的解决方案:IMO, the main advantages of WCF RIA giving simple problems simple solutions:在服务器和客户端之间重用代码的出色工具服务和客户端代码始终兼容向/从客户端/服务器传输数据相对简单对WCF RIA的强烈要求导致了易于学习的编码模式缺点使困难的问题难以解决或无法解决:The cons make hard problems hard or impossible: WCF RIA是坚决相信,并且没有遵循意见是痛苦的还是不可能的所有操作都在UI线程上返回,通常会导致性能问题有一些巫术可以最大程度地重用客户端+服务器代码WCF RIA is strongly opinionated and not following that opinion is painful or impossibleAll operations return on the UI thread, often causing performance problemsThere is some voodoo to achieve the highest amount of client+server code re-use 这篇关于在非UI线程上运行RIA服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-15 08:40