Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:21:09+00:00 2026-06-14T22:21:09+00:00

I’m playing around with the RX libraries for .NET in C#. Can anyone explain

  • 0

I’m playing around with the RX libraries for .NET in C#. Can anyone explain to me why the ‘observer.OnCompleted()’ method does nothing in the following code:

var observableStream = Observable.Create<CustomMessage>(
       (observer) =>
           {
               CustomMessage cm = new CustomMessage();
               CustomMessage.Subscribe(observer.OnNext);

               return Disposable.Create(
               () =>
                   {
                       Console.WriteLine("Disposing...");
                       CustomMessage.Unsubscribe(observer.OnNext);                          
                       observer.OnCompleted();                //***Nothing happens here***
                   }
               );
       });

    //IObserver.OnException()
    public override void OnException(Exception e)
    {
        Console.WriteLine("Exception occurred - " + e.Message);
    }

    //IObserver.OnComplete()
    public override void OnUnsubscribe()
    {
        Console.WriteLine("Unsubscribed...");            
    }

    //IObserver.OnNext()
    public override void HandleNextMsg(IRVMessage msg)
    {
        Console.WriteLine("Instance received a message");
    }

IDisposable myDisposable = observableStream.Subscribe(HandleNextMsg, OnException, OnUnsubscribe);

//At some later point....
myDisposable.Dispose();

The code is intended to make a subscription to a stream of CustomMessages. It registers the observer.OnNext() method with my CustomMessage type when setting up a subscription. It then de-registers the observer.OnNext() when disposing of the subscription. All of this works correctly. My ‘HandleNextMsg()’ method is called whenever a CustomMessage is received.

At some later point when I wish to terminate my subscription I call ‘Dispose()’ and the following two lines are successfully executed:

Console.WriteLine("Disposing...");
CustomMessage.Unsubscribe(observer.OnNext); 

I then receive no more CustomMessages. However the following line, although executed, does nothing:

observer.OnCompleted(); 

I expected it to call the line:

Console.WriteLine("Unsubscribed...");

At some point the connection between the observer and the ‘OnUnsubscribe’ method is lost and I’d like to understand exactly what’s going on. How is it that the ‘observer.OnNext()’ can be successfully de-registered, but ‘observer.OnCompleted()’ does nothing?

It’s been pointed out to me that just because I’m disposing the stream doesn’t mean I should be calling ‘OnCompleted()’ but I’d still like to understand why it doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:21:10+00:00Added an answer on June 14, 2026 at 10:21 pm

    The issue you are seeing is caused by the way Observable.Create wraps the function you passed and any observers you subscribe to the resulting IObservable. Basically, the flow is:

    • Observable.Create returns an AnonymousObservable.
    • AnonymousObservable wraps observers in an AutoDetachObserver in Subscribe.
    • AnonymousObservable returns the AutoDetachObserver (which implements IDisposable) from Subscribe.
    • AutoDetachObserver.Dispose sets its stopped flag and then disposes the object your original subscribe function returned. This flag causes the observer to ignore future calls to OnError and OnCompleted, thus causing the wrapped observer methods to not be called.

    This answer is based on v1.x of RX, but I expect this did not change in v2.0.

    If you have some code that needs to run no matter how the subscription ends (OnError, OnCompleted, or Dispose), I would suggest Observable.Finally.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.