Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

IObservable(T).Subscribe Method

Notifies the provider that an observer is to receive notifications.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
abstract Subscribe : 
        observer:IObserver<'T> -> IDisposable

Parameters

observer
Type: System.IObserver(T)

The object that is to receive notifications.

Return Value

Type: System.IDisposable
A reference to an interface that allows observers to stop receiving notifications before the provider has finished sending them.

The Subscribe method must be called to register an observer for push-based notifications. A typical implementation of the Subscribe 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 Subscribe method for an application that reports latitude and longitude information. It defines an 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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.