IObservable<'T>.Subscribe Method (IObserver<'T>)
Notifies the provider that an observer is to receive notifications.
Assembly: mscorlib (in mscorlib.dll)
The object that is to receive notifications.
Return ValueType: System.IDisposable
A reference to an interface that allows observers to stop receiving notifications before the provider has finished sending them.
Themethod must be called to register an observer for push-based notifications. A typical implementation of the method does the following:
It stores a reference to the observer in a collection object, such as a List<'T> object.
It returns a reference to an IDisposable interface. This enables observers to unsubscribe (that is, to stop receiving notifications) before the provider has finished sending them and called the subscriber's OnCompleted method.
At any given time, a particular instance of an IObservable<'T> implementation is responsible for handling all subscriptions and notifying all subscribers. Unless the documentation for a particular IObservable<'T> implementation indicates otherwise, observers should make no assumptions about the IObservable<'T> implementation, such as the order of notifications that multiple observers will receive.
The following example illustrates the IList<'T> collection object that stores references to all observers. It also returns a private class named Unsubscriber that implements the IDisposable interface and enables subscribers to stop receiving event notifications. See the Example section of the IObservable<'T> topic for the complete example.method for an application that reports latitude and longitude information. It defines an
Available since 8
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 7.0
Available since 8.1