As a general codding guideline when should one use BooleanDisposable from reactive extensions?
2 Answers
Ok, not much feedback on question, I guess its a bit niche, here it goes:
If you put using volatile bool _isDisposed
versus BooleanDisposable
the former its a cleaner design.
More information on the volatile keyword: Here

- 329
- 1
- 4
- 9
Generally, Disposing an IDisposable should be idempotent - you should be able to Dispose it multiple times without negative consequences.
The ramifications of that are that you almost never care if an IDisposable has been disposed or not. You just Dispose it when you're done.
In my time of using Rx, I haven't come across a situation where I need to know if a Disposable instance has already been disposed. Typically the Disposable objects from Rx are composed and then returned from subscriptions. Knowing whether a Disposable has been disposed is rarely useful information.
If you need to do something when a Disposable is Disposed, then you can just use Disposable.Create and do whatever you need to do in the action.
So the only guideline I'd say around BooleanDisposable is that if you think you need it, your design might be more complex than it needs to be. Similar to guidelines for Finalizers, in that respect.

- 1
- 1

- 15,518
- 10
- 52
- 48
-
good point, I was thinking more about using it internally within a class so you don't execute sensitive code more then once. – Adrian Rus Oct 01 '15 at 10:52