什么是SubscribeOn和ObserveOn之间的区别 [英] What's the difference between SubscribeOn and ObserveOn

查看:215
本文介绍了什么是SubscribeOn和ObserveOn之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现 SubscribeOn ,这使我怀疑我是否应该使用,而不是 ObserveOn 。谷歌花了我<一个href="http://social.msdn.microsoft.com/Forums/en-US/rx/thread/6944f097-00f4-42ad-8f19-d01d1aa939f4/">here和<一href="http://www.jaylee.org/post/2011/07/24/Rx-Using-the-ObserveOn-and-SubscribeOn-operators.aspx">here,但也帮助我神交的区别:它似乎令人难以置信的微妙

I just discovered SubscribeOn, which makes me wonder if I should be using that instead of ObserveOn. Google took me here and here, but neither have helped me grok the difference: it seems incredibly subtle.

(在我的情况下,我已经得到了事件的一个非GUI线程'来了',我需要使用事件数据更新控件之前在切换到GUI线程)。

推荐答案

我有一个类似的问题了一段时间回来,问这个疑问的。我认为反应(包括注释)将会回答你的问题。总结:

I had a similar problem a while back and asked this question about it. I think the responses (including the comments) there will answer your question. To summarize:

  • 如果你想在一个GUI线程更新控件,使用 ObserveOn 。如果引用 System.Reactive.Windows.Forms.dll 你的 .ObserveOn(表格)这是很方便的。
  • SubscribeOn 控制在其认购的实际调用发生的线程。在这里解决的问题是,WinForms和WPF会抛出异常,如果您从多个不同的线程添加事件处理程序。
  • If you want to update controls on a gui thread, use ObserveOn. If you reference System.Reactive.Windows.Forms.dll you get the .ObserveOn(form) which is handy.
  • SubscribeOn controls the thread on which the actual call to subscribe happens. The problem solved here is that WinForms and WPF will throw exceptions if you add event handlers from multiple different threads.

此外,<一个href="http://blogs.msdn.com/b/rxteam/archive/2009/11/21/observable-context-observable-subscribeon-and-observable-observeon.aspx">this帖子是搞清楚之间的关系非常有帮助的 ObserveOn SubscribeOn

Also, this post was very helpful in figuring out the relationship between ObserveOn and SubscribeOn.

这篇关于什么是SubscribeOn和ObserveOn之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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