简体   繁体   中英

Why Observable.FromEventPattern take in a scheduler?

Why Observable.FromEventPattern take in a scheduler?

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. However, FromEventPattern has "no notion of time" associated with it.

How does Observable.FromEventPattern use the scheduler?

The events are delivered on the specific scheduler. For example you may want your events delivered on the threadpool rather than the UI thread. You could use

Scheduler.Default

and then any downstream processing of your events will not impact the UI rendering. Of course you would then need to marshal the results back to the UI scheduler. For this switch you can use the

ObserveOnDispatcher()

method to put subsequent processing back to the UI thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM