What is a good case/example for using the ScheduledDisposable in Reactive Rx
I like the using the CompositeDisposable and SerialDisposable, but would you need the ScheduledDisposable.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The logic of using the Rx disposables is that code that performs some sort of set up operation can return an
IDisposablethat anonymously contains the code that will do the associated clean up at a later stage. If this pattern is used consistently then you can compose together many disposables to perform a single clean up operation without any specific knowledge of what is being cleaned up.The problem is that if that clean up code needs to run on a certain thread then you need some way for
Disposecalled on one thread to be marshalled to required thread – and that’s whereScheduledDisposablecomes in.The primary example is the
SubscribeOnextension method which usesScheduledDisposableto ensure that the “unsubscribe” (i.e. theDispose) is run on the sameISchedulerthat theSubscribewas run on.This is important for the
FromEventPatternextension method, for example, that attaches to and detaches from event handlers which must happen on the UI thread.Here’s an example of where you might use
ScheduledDisposabledirectly:A little contrived, but it should show a reasonable example of how you’d use
ScheduledDisposable.