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 566355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:58:07+00:00 2026-05-13T12:58:07+00:00

I am experimenting with RX, and run across the following problem (at least I

  • 0

I am experimenting with RX, and run across the following problem (at least I perceive it as a problem). The following code creates an observable, and subscribes to it twice. I thought subscriptions should act independently, so the code below would output two lines, one for each subscription, on each key press. But this is not the case, I always get only one subscription to handle a particular key stroke, semi-randomly first or second. Why this is happening and what is the “recommended” way to do multiple observers?

    static IEnumerable<ConsoleKeyInfo> KeyPresses()
    {
        for (; ; )
        {
            var currentKey = Console.ReadKey(true);

            if (currentKey.Key == ConsoleKey.Enter)
                yield break;
            yield return currentKey;
        }
    }

    static void Main()
    {
        var timeToStop = new ManualResetEvent(false);
        var keypresses = KeyPresses().ToObservable();
        keypresses.Subscribe(key => Console.WriteLine(key.Key + "1"), 
           () => timeToStop.Set());
        keypresses.Subscribe(key => Console.WriteLine(key.Key + "2"), 
           () => timeToStop.Set());
        timeToStop.WaitOne();
    }
  • 1 1 Answer
  • 3 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-05-13T12:58:07+00:00Added an answer on May 13, 2026 at 12:58 pm

    The reason for this particular behavior was that the observable was cold. Meaning each subscriber was consuming the ReadKey call on .GetNext(). As soon as I “warmed up” the observable by calling

    var keypresses = KeyPresses().ToObservable().Publish(); 
    

    each subscriber received its own value.

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

Sidebar

Related Questions

I am experimenting with synth styles and i came across the following problem for
I am experimenting with pointers and strings. In the following code, everything is tested
I have been experimenting with LINQ to XML and have run across a very
I've been experimenting with Lucene on Google's App Engine and have run across index
I run this code for experimenting copy constructor and assignment operator class AClass {
Im experimenting with the following code private void timer1_Tick(object sender, EventArgs e) { Thread
I've been experimenting with ASP.Net MVC, and have come across a problem that is
I am experimenting with multithreading in Delphi (XE) and have run into a problem
I'm experimenting with QtWebkit and Google Maps. The problem I've run into is calling
I am experimenting with WPF and I came across a problem I can't seem

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.