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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:56:29+00:00 2026-05-16T18:56:29+00:00

Given the benefits of composable events as offered by the Reactive Extensions (Rx) framework

  • 0

Given the benefits of composable events as offered by the Reactive Extensions (Rx) framework, I’m wondering whether my classes should stop pushing .NET events, and instead expose Rx observables.

For instance, take the following class using standard .NET events:

public class Foo
{
   private int progress;
   public event EventHandler ProgressChanged;

   public int Progress
   {
      get { return this.progress; }
      set
      {
         if (this.progress != value)
         {
            this.progress = value;

            // Raise the event while checking for no subscribers and preventing unsubscription race condition.
            var progressChanged = this.ProgressChanged;
            if (progressChanged != null)
            {
                progressChanged(this, new EventArgs());
            }
         }
      }
   }
}

Lot of monotonous plumbing.

This class could instead use some sort of observable to replace this functionality:

public class Foo
{
   public Foo()
   {
       this.Progress = some new observable;
   }

   public IObservable<int> Progress { get; private set; }
}

Far less plumbing. Intention is no longer obscured by plumbing details. This seems beneficial.

My questions for you fine StackOverflow folks are:

  1. Would it good/worthwhile to replace standard .NET events with IObservable<T> values?
  2. If I were to use an observable, what kind would I use here? Obviously I need to push values to it (e.g. Progress.UpdateValue(…) or something).
  • 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-16T18:56:30+00:00Added an answer on May 16, 2026 at 6:56 pm

    I don’t recommend managing your own subscriber list when there are built in subjects that can do that for you. It also removes the need for carrying your own mutable copy of T.

    Below is my (commentless) version of your solution:

    public class Observable<T> : IObservable<T>, INotifyPropertyChanged 
    { 
        private readonly BehaviorSubject<T> values; 
    
        private PropertyChangedEventHandler propertyChanged; 
    
        public Observable() : this(default(T))
        {
        } 
    
        public Observable(T initalValue) 
        { 
            this.values = new BehaviorSubject<T>(initalValue);
    
            values.DistinctUntilChanged().Subscribe(FirePropertyChanged);
        }
    
        public T Value 
        { 
            get { return this.values.First(); } 
            set { values.OnNext(value); } 
        }
    
        private void FirePropertyChanged(T value)
        {
            var handler = this.propertyChanged;
    
            if (handler != null)
                handler(this, new PropertyChangedEventArgs("Value"));
        }
    
        public override string ToString() 
        { 
            return value != null ? value.ToString() : "Observable<" + typeof(T).Name + "> with null value."; 
        } 
    
        public static implicit operator T(Observable<T> input) 
        { 
            return input.Value; 
        } 
    
        public IDisposable Subscribe(IObserver<T> observer) 
        { 
            return values.Subscribe(observer);
        } 
    
        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged 
        { 
            add { this.propertyChanged += value; } 
            remove { this.propertyChanged -= value; } 
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any benefits to limiting the number of concurrent threads doing a given
One of the benefits of ASP.NET MVC I keep reading about is that it's
I'm just wondering if Specification pattern is pointless, given following example: Say you want
Given that .Net has the ability to detect bitness via IntPtr (looking through reflector
I'm working with ASP.NET MVC but this really applies to any MVC framework. I
I was wondering what the benefits of using user IDs were rather than just
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
Given a package, how can I automatically find all its sub-packages?
Given these two queries: Select t1.id, t2.companyName from table1 t1 INNER JOIN table2 t2
Given a date range how to calculate the number of weekends partially or wholly

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.