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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:36:29+00:00 2026-05-20T12:36:29+00:00

In the following code if I understand joins in RX correctly, I should see

  • 0

In the following code if I understand joins in RX correctly, I should see the following alerts occur:

  • West
  • Test
  • Test-West*
  • Done

I get 3 of the 4 alerts I expect… why aren’t I receiving “Test-West” as well?

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent(); 

        var loginInitial = new LoginInitial();
        var loginCheckList = new LoginCheckList();



        var result1 = from x in loginInitial.Status
                    from y in loginCheckList.Status
                    where x == "Test" && y == "West"
                    select new { x, y };

        result1.Subscribe(x => MessageBox.Show(x.x + "-" + x.y));

        var result2 = from x in loginInitial.Status
                      where x == "Test"
                      select x;

        result2.Subscribe(x => MessageBox.Show(x));

        var result3 = from x in loginCheckList.Status
                      where x == "West"
                      select x;

        result3.Subscribe(x => MessageBox.Show(x));

        var task1 = Task.Factory.StartNew(() =>
                                  {
                                      for (int i = 0; i < 10000000; i++)
                                      {
                                          if (i == 9000000)
                                              loginInitial.Status.Publish("9000000");
                                          if (i == 9000001)
                                              loginInitial.Status.Publish("Test");
                                      }
                                  });

        var task2 = Task.Factory.StartNew(() =>
                                  {
                                        for (int i = 0; i < 1000000; i++)
                                        {
                                            if (i == 800000)
                                                loginInitial.Status.Publish("800000");
                                            if (i == 800001)
                                                loginCheckList.Status.Publish("West");
                                        }
                                  });
        Task.WaitAll(task1, task2);

        MessageBox.Show("Done");
    }
}

public class LoginInitial
{
    public PublishObservable<string> Status = new PublishObservable<string>(); 
}

public class LoginCheckList
{
    public PublishObservable<string> Status = new PublishObservable<string>();
}

public class PublishObservable<T> : IObservable<T>
{
    private IList<IObserver<T>> _observers = new List<IObserver<T>>();

    public void Publish(T value)
    {
        lock (_observers)
        {
            foreach (var observer in _observers)
            {
                observer.OnNext(value);
            }
        }
    }

    public void Complete()
    {
        lock (_observers)
        {
            foreach (var observer in _observers)
            {
                observer.OnCompleted();
            }
        }
    }

    public IDisposable Subscribe(IObserver<T> observer)
    {
        lock (_observers)
        {
            _observers.Add(observer);
        }
        return null;
    }
}
  • 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-05-20T12:36:29+00:00Added an answer on May 20, 2026 at 12:36 pm

    Tomas Petricek pretty much explains why this is happening. I’ll just add a solution as an example.

    As well as adjusting result1 to use CombineLatest (which also needs to use extension method syntax as opposed to linq syntax), I’ve changed the implementation to use Subject which will remove the need to create your own implementation of IObservable. I’ve also changed your implementations that uses multiple subscriptions into a single subscription by mergin geach result observable through Observable.Merge.

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent(); 
    
            var loginInitial = new Subject<String>();
            var loginCheckList = new Subject<String>();
    
            var result1 = loginInitial.CombineLatest(loginCheckList, 
                    (x, y) => new Tuple<string, string>(x, y))
                .Where(latest => latest.Item1 == "Test" && latest.Item2 == "West")
                .Select(latest => string.Format("{0} - {1}", latest.Item1, latest.Item2));
    
            var result2 = from x in loginInitial
                            where x == "Test"
                            select x;
    
            var result3 = from x in loginCheckList
                            where x == "West"
                            select x;
    
            Observable.Merge(result1, result2, result3)
                .Subscribe(Console.WriteLine);
    
            var task1 = Task.Factory.StartNew(() =>
            {
                for (int i = 0; i < 10000000; i++)
                {
                    if (i == 9000000)
                        loginInitial.OnNext("9000000");
                    if (i == 9000001)
                        loginInitial.OnNext("Test");
                }
            });
    
            var task2 = Task.Factory.StartNew(() =>
            {
                for (int i = 0; i < 1000000; i++)
                {
                    if (i == 800000)
                        loginInitial.OnNext("800000");
                    if (i == 800001)
                        loginCheckList.OnNext("West");
                }
            });
    
            Task.WaitAll(task1, task2);
    
            Console.WriteLine("Done");
        }
    }
    

    Note 1 – I’ve used CombineLatest here but you could just as easily change it to use Zip depending on the behavior you need. Check out the marble diagrams on the RxAs pages for Zip and CombineLatest for a better idea of how each behaves.

    Note 2 – I would probably change result2 and result3 to use extension method syntax so that there isn’t a mix of approaches in one method. Nothing wrong with it the way it is but I’d prefer the consistency of using one type of syntax where possible.

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

Sidebar

Related Questions

the following code is not behaving like I would expect. Please help me understand
Please see the following code to understand my question better. class compareByValue { public:
The following code produces the result I don't understand this. Any ideas why? If
The following code crashes and burns and I don't understand why: DateTime dt =
I don't understand why the following code generates a warning. interface Generic<T> { }
if wrote the following code and do not understand why the trace returns false:
I have the following code and I can't understand what does it mean: var1
I am having following code but unable to understand as to why no match
I don't understand why in the following code, when I instanciate an object of
I dont understand what would be the problem with the following code. It needs

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.