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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:17:31+00:00 2026-06-09T19:17:31+00:00

How I could convert the MainEngine Observable to Cold ? from this example: public

  • 0

How I could convert the MainEngine Observable to Cold ? from this example:

    public IObservable<int> MainEngine
    {
        get
        {
            Random rnd = new Random();
            int maxValue = rnd.Next(20);
            System.Diagnostics.Trace.TraceInformation("Max value is: " + maxValue.ToString());

            return (from sinlgeInt in Enumerable.Range(0, maxValue)
                    select sinlgeInt).ToObservable();
        }
    }

    public void Main()
    {
        // 1
        MainEngine.Subscribe(
                onNext: (item) => { System.Diagnostics.Trace.TraceInformation("Value is: " + item.ToString()); }
        );

        // 2
        MainEngine.Subscribe(
                onNext: (item) => { System.Diagnostics.Trace.TraceInformation("Gonna put it into XML: " + item.ToString()); }
        );
    }

Question 1: On subscriber 1 and subscriber 2 I get a different results but I want both of them receive the same results.

Question 2: From the point in time when I add the second subscriber both of them continue to receive the same results.

  • 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-09T19:17:33+00:00Added an answer on June 9, 2026 at 7:17 pm

    Regarding your first question, the issue is that the observers are not subscribing to the same IObservable since you call the getter twice.

    Assigning the IObservable to a local variable seems to fix the issue:

    IObservable<int> mainEngine = MainEngine;
    
    mainEngine.Subscribe(onNext: (item) => { /* ... */ });
    mainEngine.Subscribe(onNext: (item) => { /* ... */ });  
    

    Regarding your second question, if you would like to share a subcription to a single IObservable, you can use the Publish method:

    IConnectableObservable<int> published = MainEngine.Publish();
    
    published.Subscribe(onNext: (item) => { Console.WriteLine(item + " on observer 1"); });
    published.Subscribe(onNext: (item) => { Console.WriteLine(item + " on observer 2"); });
    
    published.Connect();
    

    The two subscribers will then see the results from the IObservable in an interleaved fashion:

    0 on observer 1
    0 on observer 2
    1 on observer 1
    1 on observer 2
    etc.
    

    You can also subscribe new observers after the call to Subscribe, after which point all subscribers will see the same events. You can modify your example to test this, by running your observable on a new thread and introducing a delay:

    public static void Main()
    {
        Random rnd = new Random();
        int maxValue = rnd.Next(20);
    
        /* Zip with Observable.Interval to introduce a delay */
        IObservable<int> mainEngine = Observable.Range(0, maxValue, Scheduler.NewThread)
            .Zip(Observable.Interval(TimeSpan.FromMilliseconds(100)), (a, b) => a);
    
        /* Publish the observable to share a subscription between observers */
        IConnectableObservable<int> published = mainEngine.Publish();
    
        /* Subscribe the first observer immediately, events are not yet being observed */
        published.Subscribe(onNext: (item) => { Console.WriteLine(item + " on observer 1"); });
    
        /* Start pushing events to the first observer */
        published.Connect();
    
        /* Wait one second and then subscribe the second observer */
        Thread.Sleep(1000);
        published.Subscribe(onNext: (item) => { Console.WriteLine(item + " on observer 2"); });
    
        Console.ReadKey();
    }
    

    You will see one second’s worth of events only on the first observer, and then both observers will see each event simultaneously.

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

Sidebar

Related Questions

I would like to know if someone could convert this little code from as3
Anyone know of a nice efficient function that could convert, for example: HelloWorld -->
How could i convert this string 03/16/2012 03:22PMusing php to store in datetime format
Could anyone please help me convert this code to vb.net, I have tried it
Could someone please help me to convert this String into a Map ... String
I need a method which could convert a given date from one time zone
Can anyone explain to me how I could convert this sample function to use
Afternoon all, I have this query and was wondering how i could convert this
How could I convert a VimOutliner file to Markdown? In other words, I how
I would like to ask how could I convert a string which inserted by

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.