IObserver<T> Interface
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Provides a mechanism for receiving push-based notifications.
Assembly: mscorlib (in mscorlib.dll)
Type Parameters
- in T
The object that provides notification information.
This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived. For more information about covariance and contravariance, see [2678dc63-c7f9-4590-9ddc-0a4df684d42e].
The IObserver<T> type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | OnCompleted | Notifies the observer of the end of the observable sequence. No further values or notifications will be made available for this sequence. |
![]() | OnError | Notifies the observer that an exception has occurred in processing the observable sequence. |
![]() | OnNext | Notifies the observer of a new value in the observable sequence. |
Provides a mechanism to support push-style iteration over an observable sequence for publish/subscribe event processing.
The IObserver<T> and IObservable<T> interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. The IObservable<T> interface represents the class that sends notifications (the provider); the IObserver<T> interface represents the class that receives them (the observer). T represents the class that provides the notification information.
An IObserver<T> implementation arranges to receive notifications from a provider (an IObservable<T> implementation) by passing an instance of itself to the provider's IObservable<T>.Subscribe method. This method returns an IDisposable object that can be used to unsubscribe the observer before the provider finishes sending notifications.
The IObserver<T> interface defines the following three methods that the observer must implement:
The OnNext method, which is typically called by the provider to supply the observer with new data or state information.
The OnError method, which is typically called by the provider to indicate that data is unavailable, inaccessible, or corrupted, or that the provider has experienced some other error condition.
The OnCompleted method, which is typically called by the provider to indicate that it has finished sending notifications to observers.
