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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:30:48+00:00 2026-05-28T08:30:48+00:00

I am trying to implement a simple Observer pattern using .net Observable class. I

  • 0

I am trying to implement a simple Observer pattern using .net Observable class. I have code that looks like this:

Observable.FromEventPattern<PropertyChangedEventArgs>(
    Instance.User,
    "PropertyChanged")
          .Where(e => e.EventArgs.PropertyName == "FirstName")
          .ObserveOn(Scheduler.ThreadPool)
          .Subscribe(search => OnFirstNameChanged(search.EventArgs));

Observable.FromEventPattern<PropertyChangedEventArgs>(
    Instance.User,
    "PropertyChanged")
          .Where(e => e.EventArgs.PropertyName == "LastName")
          .ObserveOn(Scheduler.ThreadPool)
          .Subscribe(search => OnLastNameChanged(search.EventArgs));

I want the observers to run on a background thread, but I want them to all run on the same background thread (for our real implementation, it will be too complicated to have every listener on a different thread).

i.e. I want all of the OnXXXChanged logic to be performed on a thread other than the UI thread, but instead of Observing on the entire threadpool, I want to make sure they run in the correct order, on the same thread.

How should the above be modified?

Also, on a somewhat related note, are there any good sample code examples using the Observable class to implement this pattern?

  • 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-28T08:30:49+00:00Added an answer on May 28, 2026 at 8:30 am

    You should create an EventLoopScheduler and use that single instance in all calls to ObserverOn:

    var scheduler = new EventLoopScheduler(ts => new Thread(ts));
    
    ... .ObserveOn(scheduler). ...
    

    The thread created by the factory method is the thread used to schedule the execution on. By leaving the property ExitIfEmpty set to false this thread will not terminate even if there is nothing to do meaning that it will be reused for every call.

    However, you could also consider using Scheduler.NewThread. Using that scheduler will allow the thread to terminate if there is nothing more to do. When more work is queued up by ObserverOn a new thread will be created but only a single thread should ever exists meaning that you don’t have synchronize different observers.

    The threads created by EventLoopScheduler (which is used by Scheduler.NewThread) are named Event Loop #. You will see these names in the debugger.

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

Sidebar

Related Questions

I'm trying to implement simple Event Bus I started like this: public class RegistrationData
I'm trying to implement a simple ActionLink that will delete records using ASP.NET MVC.
I'm trying to implement Simple chat using Servlet 3.0 and Comet pattern based on
I'm trying to implement this simple example of how to synchronize threads using pthread
I'm trying to implement an MVP pattern using STL and I have used *shared_ptr*
Trying to implement a simple print in SL4. I have a DataGrid that I
I'm trying to implement a simple search, using LIKE in my SQL statement: Using
I'm trying to implement a simple horizontal navigation menu that just shows a single
I am trying to implement a simple request to Wikipedia's API using AJAX (XMLHttpRequest).
I am now trying to implement a simple HTML webpage scraper using Java.Now 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.