Noob Noob - 1 year ago 187
C# Question

Reactive Observable Subscription Disposal

If I have access to an IObservable that I know is only ever going to return one item, will this work and is it the best usage pattern?

IDisposable disposable = null;
disposable = myObservable.Subscribe(x =>
if (disposable != null)

Answer Source

Disclaimer: I'm also still learning Rx. So I'm not really an expert but I believe the disposable returned by Subscribe will only unsubscribe the subscription. Also if the source completes, like in your case, the unsubscription is done automatically. So I think the Dispose there is redundant and can be safely removed.

See the answer to this question for more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download