[英]Why Observable.FromEventPattern take in a scheduler?
Why Observable.FromEventPattern take in a scheduler? 为什么Observable.FromEventPattern接受调度程序?
IObservable<EventPattern<TEventArgs>> FromEventPattern<TEventArgs>(Action<EventHandler<TEventArgs>> addHandler, Action<EventHandler<TEventArgs>> removeHandler, IScheduler scheduler)
I can understand why time-based operators like Throttle and Delay take in scheduler. 我能理解为什么像Throttle和Delay这样基于时间的运算符会加入调度程序。 However, FromEventPattern has "no notion of time" associated with it.
但是,FromEventPattern具有“无时间概念”关联。
How does Observable.FromEventPattern use the scheduler? Observable.FromEventPattern如何使用调度程序?
The events are delivered on the specific scheduler. 事件在特定的调度程序上传递。 For example you may want your events delivered on the threadpool rather than the UI thread.
例如,您可能希望事件在线程池而不是UI线程上传递。 You could use
你可以用
Scheduler.Default Scheduler.Default
and then any downstream processing of your events will not impact the UI rendering. 然后对事件的任何下游处理都不会影响UI呈现。 Of course you would then need to marshal the results back to the UI scheduler.
当然,您随后需要将结果封送回UI调度程序。 For this switch you can use the
对于此开关,您可以使用
ObserveOnDispatcher() ObserveOnDispatcher()
method to put subsequent processing back to the UI thread. 方法,将后续处理放回UI线程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.