Editar

Partilhar via


IObserver<T>.OnCompleted Method

Definition

Notifies the observer that the provider has finished sending push-based notifications.

public:
 void OnCompleted();
public void OnCompleted ();
abstract member OnCompleted : unit -> unit
Public Sub OnCompleted ()

Examples

The following example provides an implementation of the OnCompleted method in a latitude/longitude tracking application. The method simply reports that no further data is available and calls the provider's IDisposable.Dispose implementation. See the Example section of the IObserver<T> topic for the complete example.

public virtual void OnCompleted()
{
   Console.WriteLine("The Location Tracker has completed transmitting data to {0}.", this.Name);
   this.Unsubscribe();
}
member this.OnCompleted() =
    printfn $"The Location Tracker has completed transmitting data to {name}."
    this.Unsubscribe()
Public Overridable Sub OnCompleted() Implements System.IObserver(Of Location).OnCompleted
   Console.WriteLine("The Location Tracker has completed transmitting data to {0}.", Me.Name)
   Me.Unsubscribe()
End Sub

Remarks

When the observer's OnCompleted implementation is called, the OnCompleted method can optionally call the Dispose method of the IDisposable object that was returned to the observer when it called the IObservable<T>.Subscribe method.

Applies to