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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:03:07+00:00 2026-06-12T09:03:07+00:00

I am new to Rx and was going through some samples and came across

  • 0

I am new to Rx and was going through some samples and came across the below:

    Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(
            h => new RoutedEventHandler(h),
            h => Loaded += h,
            h => Loaded -= h)
            .Select(_ => true)
            .StartWith(IsLoaded)
            .Where(l => l)
            .Take(1)
            .Subscribe(_ => Console.WriteLine("loaded");

I am trying to deconstruct this statement to figure out what it is doing but it is not 100% clear to me.

I understand how FromEventPattern is turning the Loaded event into an observable sequence. Now, Select is going to trigger when IsLoaded is true (that is what I am assuming). Is Select just getting its info from the RoutedEventArgs?

Now, I am not sure why StartsWith is there. StartsWith will prepend a sequence of values to an observable sequence. So is it just adding the value of IsLoaded to the beginning of the list? Wouldn’t it already be there after Select happens?

.Where is not applying any sort of filter so .Take will just take the first value of the sequence (which in this case is not used any further). Then it Subscribes and the Console is written to only when the control is loaded.

Is this analysis mostly correct?

Also, any tips on debugging such things (meaning, what the sequence looks like during different stages of the chain)? I can get info just by attaching the debugger but I was wondering if there are any other tricks/tips that might be commonly used.

  • 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-12T09:03:08+00:00Added an answer on June 12, 2026 at 9:03 am

    Most of the Observable operators work the same way the Enumerable operators of the same name. If you have experience using those, it will be useful here.

    So to work through this, let’s use an array of integer instead of the observable for a moment.

    int[] data = {1, 2, 3, 4};
    

    This changes the expression to

    var results = data.Select(_ => true) 
                      .StartWith(IsLoaded)
                      .Where(l => l)
                      .Take(1);
    foreach (var r in results)
    {
        Console.WriteLine("loaded");
    }
    

    If you made an array at each stage in the expression you would get:

    Select - {true, true, true, true}
    StartWith - {value of IsLoaded, true, true, true, true}
    Where - (if IsLoaded is true)  {true, true, true, true, true}
            (if IsLoaded is false) {true, true, true, true}
    Take - {true}
    

    With IEnumerables, doing this sort of thing doesn’t make much sense because you will always get one value that is true (unless the source array is empty and IsLoaded is false).

    The use of this with an IObservable is to make something that will produce one signal when the object is loaded.

    • The StartWith is provides the signal if the object is already loaded at the time of subscription.
    • However, if the object is not loaded, IsLoaded will be false, the Where will filter it out, and when the event fires, it will trigger a notification.
      • The Select will ignore the actual data produced by the event and simply pass a true, which will proceed through the Where filter.
    • The Take is used to only trigger the notification once, regardless of it it comes from the StartWith, because the object was already loaded, or the event (via Select), when loading completes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been going through some old code, where I came across some custom defined
Going through some tutorials about sockets, I keep coming across code like that: while(true){
I was going through some old code of mine and came across a hybrid
I'm going through some new code I just wrote and adding NDoc sytle comments
I'm new to Android development and I'm currently going through some tutorials. When I
I am new to python, and was going through some pre written code to
I am working my way through some samples, and came up with this working
i am new to iphone development and i am going through tutorial and some
I'm fairly new the functional programming, so I'm going through some practice exercises. I
I'm beginning with backbone.js Going through some tutorials, like the one shown below. I

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.