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

  • Home
  • SEARCH
  • 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 6821499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:33:08+00:00 2026-05-26T21:33:08+00:00

This is a question about how to use Reactive Extensions (Rx) in a specific

  • 0

This is a question about how to use Reactive Extensions (Rx) in a specific event-related scenario.

  • The aim is to take a number of classes that trigger some event
  • And congregate them into one IObservable that can be subscribed to by any clients (unaware of the event classes).
  • Note the events of interest use subclassed EventArgs

Some Custom EventArgs

public class HappenedEventArgs : EventArgs
{
    internal bool IsBadNotGood;
}

Many Separate Classes Where Happened Events Occur

public class EventSourceA : IEventSource {

    public event HappenedEventHandler Happened;
    private void OnHappened(HappenedEventArgs e)
    {
        if (Happened != null)
            Happened(this, e);
    }
    // And then this class calls OnHappened(e) whenever it decides to ...
}

public class EventSourceB : IEventSource {

    public event HappenedEventHandler Happened;
    private void OnHappened(HappenedEventArgs e)
    {
        if (Happened != null)
            Happened(this, e);
    }
    // And then this class also calls OnHappened(e) at times ...
}

public interface IEventSource
{
    event HappenedEventHandler Happened;
}

public delegate void HappenedEventHandler(object sender, HappenedEventArgs e);

How to Congregate All Those Events and Expose a United Event Front

public class Pooler{

    private IObservable<X> _pool;

    public IObservable<X> Subscribe(){
        return _pool;        
    }

    public void Register(IEventSource item)
    {
        // How to take item.Happened and inject/bind it into _pool here?
    }        

    internal void Unregister(IEventSource item)
    {
        // Disconnect item.Happened from _pool
    }

    public Pooler(){
        // Instantiate _pool to whatever is best?
        // _pool = ...
    }

 }

A Subscriber Who Doesnt Know Anything About EventSources Directly

 static void Try() {
     var pooler = new Pooler();
     pooler.Subscribe().Subscribe(e =>
            {
                 // Do something with events here, as they arrive
            }
     );
     // ....
     // Wherever whenever:
     AddEventSources(pooler);
 }

 static void AddEventSources(Pooler pooler){
     var eventSourceA = new EventSourceA();
     pooler.Register(eventSourceA);
     var eventSourceB = new EventSourceB();
     pooler.Register(eventSourceB);     
 }
  • 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-26T21:33:09+00:00Added an answer on May 26, 2026 at 9:33 pm

    What the Rx library tries to provide are ways of handling situations such as these without having to create a bunch of classes/methods that manually propagate observables.

    Let’s say you had a class with an event:

    public class EventedClass
    {
        public event Action<EventArgs> Event;
    }
    

    And an enumerable of those instances IEnumerable<EventedClass> objects,
    you can use LINQ to project observables out of those classes, combine them with Observable.Merge which will give you the combined sequential output of those events.

    Observable.Merge(
        objects.Select(
            o => Observable.FromEvent<EventArgs>(
                handler => o.Event += handler,
                handler => o.Event -= handler
            )
    )).Subscribe(args => 
    { 
        //do stuff
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a question about the use of type classes in Haskell. I get
This question is about best use scenarios in projects with ORMs like NHibernate, Subsonic,
i'm just curious. so i ask this particular question about SQLite. I haven't use
This question is not about 'best' barcode library recommendation, we use various products on
This question is NOT about race-conditions, atomicity, or why you should use locks in
Help settle the debate that's going on in the comments at this question about
I have asked this question about using the a Linq method that returns one
I'm revisiting and re-implementing the code that caused me to ask this question about
This is a bit of subjective question about a specific situation. Main goal for
Taking this question about beautiful XSL but getting more specific, how should I refactor

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.