在非UI线程上运行RIA服务 [英] Run RIA service on non UI thread

查看:77
本文介绍了在非UI线程上运行RIA服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从非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.

  • 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:

域上下文加载和SubmitChanges异步执行.他们从线程池中获取一个线程,对服务器进行必要的调用,当这些调用完成时,工作将自动编组回UI线程,以修改实体集合并随后更新UI(可能通过INotificationChanged).

如果使用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 impossible
  • All operations return on the UI thread, often causing performance problems
  • There is some voodoo to achieve the highest amount of client+server code re-use

这篇关于在非UI线程上运行RIA服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆