With BehaviorSubject<T>
you are guaranteed* to have a First
value always available.
However, IObservable<T>
query operators can't work under that assumption in general, so the Obsolete
attribute was added to drive people towards asynchronous methods like FirstAsync
- helping them to "fall into the pit of success".
Because of the special case of BehaviorSubject<T>
always having a value set, it has a thread safe Value
property. So, assuming that you have something like this:
var subject = new BehaviorSubject<string>("Some value");
Then you can do this:
var current = subject.Value;
*Attempting to acess the value of a BehaviorSubject<T>
instance after its Dispose
method has been called, whether by the Value
property or a query operator like FirstAsync
, will cause an ObjectDisposedException
to be thrown.