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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:30:14+00:00 2026-06-01T03:30:14+00:00

Execution Context nested Events Hi, I would like to know a little bit more

  • 0

Execution Context nested Events

Hi,
I would like to know a little bit more about the execution context of an IObserver<T> and related to “nested events”.

Basically when I compare it to linq-to-IEnumerable, I build up an expression tree and I gets executed when I call something like ToList()… etc.
For example

Var singleCustomer = from customer in customers
            Where customer.ID == 2
            Select customer.FirstOrDefault();

This is only an expression which gets executed (I assume when I execute FirstOrDefault)…
How does this work with the IObservable world? I assume it would work almost the same… I would be great to have some input on this…

This relates to my real question because I have some Event which is some sort of an event container.

event EventHandler<ContainerEventArgs> ContainerReady;

and the ContainerEventArgs would contain an Array of Coordinates… And I have to do an operation there to get out the particular coordinates (centercoordinate) I am looking for.
The centercoordinates would the thing I really like to observe on. WhenEver this changes I would like to get Notified,..

In the standard .Net way without Rx I would do something like this to get my Coordinate Change Event for the CenterCoordinate.

ContainerReady += (s,e) => {
var container = e.GetContainer();
var coordinate = new point[e.CoordinatesArrayLength]();
e.CopyCoordinatesToArray(container);
if(coordinates != null){
  var particularCoordinate = from coordinate in coordinates.where(… center coordinates…).FirstOrDefault();
if(particularCoordinate != null){
  if(CenterCoordinateUpdated != null)
     {
        CenterCoordinateUpdated(this, new CenterCoordinateUpdatedEventArgs(){
           CenterPosition = particularCoordinates;
          }
     }
}

}

Assuming I have some second event like this:

event EventHandler<CenterCoordinatesUpdatedEventArgs> CenterCoordinateUpdated;

Ok long story … now How should I handle this with RX? What I have so far is this:

public IObservable<Container> GetContainers(){
     var containerSource = Observerable.FromeEventPattern< ContainerEventArgs>(this,”ContainerReady”);
var container = from evt in containerSource.Where(x=>x.EventArgs.GetContainer != null)
select evt.GetContainers();
return container;
}

So this returns an IObservable<Container>() but like I said I am more interested in the inner values …

I came up with this…

public IObservable<CenterCoordinates> GetContainers(){
     var containerSource = Observerable.FromeEventPattern< ContainerEventArgs>(this,”ContainerReady”);
var container = from evt in containerSource.Where(x=>x.EventArgs.GetContainer != null)
select evt.GetContainers();
var centerCoordinate = from cc in container
             select GetCenterCoordinates(cc); //Get CenterCoordinates does the Array copy stuff
return centerCoordinate.SkipWhile(x=>x … center condition… );
}

Does my SkipWhile and GetCenterCoordinates methods make sense? Or do I subscribe anyway to any event (related to my intro with IEnumerable) because I need to unpack the coordinates first?…When is the Observable Expression-Tree executed? Or do I not need to pay attention on that(performance)?
Is there a better way to handle this using Subjects or publish other events? Is this RX-Style? Any improvement suggestions?

  • 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-01T03:30:15+00:00Added an answer on June 1, 2026 at 3:30 am

    Your requirement are really suited for Rx, you just need a little more practice 🙂

    Let me try and help. I hope I got your requirements right.

    Your query could be written in this simple way:

    public IObservable<CenterCoordinates> GetContainers()
    {
        var containerSource = Observerable.FromeEventPattern<ContainerEventArgs>(this, "ContainerReady");
    
        var query = containerSource
            .Select(ev => ev.EventArgs.GetContainer) // project event args into containers
            .Where(container => container != null) // filter null containers
            .SelectMany(container => GetCenterCoordinates(container))  // expand the stream of containers into a stream of center coordinates
            .Where(cc => .. center condition ..);  // filter only center that match a certain condition
    
        return query;
    }
    

    if you prefer the query syntax, you can also write it like this:

    public IObservable<CenterCoordinates> GetContainers()
    {
        var containerSource = Observerable.FromeEventPattern<ContainerEventArgs>(this, "ContainerReady");
    
        var query = from ev in containerSource
                    let container = ev.EventArgs.GetContainer
                    where container != null
                    from cc in GetCenterCoordinates(container)
                    where cc .. center condition ..
                    select cc;
    
        return query;
    }
    

    Get familiar with SelectMany: it is one of the most important operators in LINQ (both LINQ to objects, and Rx).

    And a small correction: the LINQ queries that we’re talking about here are not translated by the compiler into expression trees. They are translated into a chain of extension methods, like I’ve shown in my first example. Expression trees are used in more complex scenarios (e.g. LINQ to SQL).

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

Sidebar

Related Questions

Does the Grand Central Dispatch API allow an execution context (thread) to query any
How would you extract nested try/finally blocks from a routine into a reusable entity?
My list is nested under two headers and I don't know how to access
During execution, how can a java program tell how much memory it is using?
Out of order execution in CPUs means that a CPU can reorder instructions to
By code snippet execution, I mean the ability to write a few lines of
The current GPU execution and memory models are somehow limited (memory limit, limit of
If I run the execution plan of an sp, Management Studio suggests an index.
Problem: during execution, instances of classes that derives from System.Workflow.ComponentModel.Activity is serialized by the
Error context: Visual Studio 2010 Service Pack 1 ASP.NET MVC 3 Application IE9 with

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.