Cross Flow Exception When Using RX Throttle

I get

Invalid access to multiple threads.

When using RX Throttle

Here is my code:

        yObs.SubscribeOnDispatcher()
            .DistinctUntilChanged()
            .Throttle(TimeSpan.FromMilliseconds(33))
            .SkipWhile(y => !_isDragging)
            .Subscribe(y =>
                           {
                               // Exception when trying to access image
                               image.RenderTransform = new CompositeTransform() { TranslateY = -y };
                               _vm.UpdateContentDrag(y / image.ActualHeight * 100);
                           });

But if I lower the gas, everything works.

As I understand it, Throttle uses a thread pool, so OnNext does not happen in the user interface thread. But SubscribeOnDispatcher has to translate it back into the user interface thread. Is not it?

+5
source share
2 answers

Your understanding of SubscribeOnDispatcher is incorrect. First of all, let the two * On statements be distinguished:

  • SubscribeOn * - Starts (un) a subscription to the specified scheduler. It is rarely used if you are not playing with Observable.Create, etc.
  • ObserveOn * - (OnNext, OnError, OnCompleted) . " ", .

, , ObserveOn . - . concurrency , Throttle ( - ). , , * On.

Throttle . , concurrency, . , , IObservable, , * On.

+12

:

.Throttle(TimeSpan.FromMilliseconds(33), DispatcherScheduler.Instance)

( 33 - , , )

+4

All Articles