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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:12:16+00:00 2026-06-06T20:12:16+00:00

I have 2 DecimalUpDown controls, num_one and num_two, bound to properties First and Second

  • 0

I have 2 DecimalUpDown controls, num_one and num_two, bound to properties First and Second respectively. When First is changed it will contact a server to calculate the value of Second, and vice-versa. Firing the server calls asynchronously freed the UI but, upon quick firing (scroll wheel for example), the last request isn’t always the last to return so the values may become out of sync.

Using Reactive I’m trying to Throttle the calls to only fire the server call after the user has stopped making changes for a little while. The problem is that when you make a change during an update, the Properties changing start triggering each other and get stuck in back and forth depending on the TimeSpan of the Throttle.

    public MainWindow()
    {
        InitializeComponent();

        DataContext = this;

        Observable.FromEventPattern<RoutedPropertyChangedEventHandler<object>, RoutedPropertyChangedEventArgs<object>>(h => num_one.ValueChanged += h, h => num_one.ValueChanged -= h)
            .Throttle(TimeSpan.FromMilliseconds(100), Scheduler.ThreadPool)
           .Subscribe(x =>
           {
               Thread.Sleep(300); // simulate work
               Second = (decimal)x.EventArgs.NewValue / 3.0m;
           });

        Observable.FromEventPattern<RoutedPropertyChangedEventHandler<object>, RoutedPropertyChangedEventArgs<object>>(h => num_two.ValueChanged += h, h => num_two.ValueChanged -= h)
            .Throttle(TimeSpan.FromMilliseconds(100), Scheduler.ThreadPool)
           .Subscribe(x =>
           {
               Thread.Sleep(300); // simulate work
               First = (decimal)x.EventArgs.NewValue * 3.0m;
           });
    }

    private decimal first;
    public decimal First
    {
        get { return first; }
        set
        {
            first = value;
            NotifyPropertyChanged("First");
        }
    }

    private decimal second;
    public decimal Second
    {
        get { return second; }
        set
        {
            second = value;
            NotifyPropertyChanged("Second");
        }
    }
  • 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-06T20:12:19+00:00Added an answer on June 6, 2026 at 8:12 pm

    There’s an inbuilt Rx operator that can help you do exactly what you want without using Throttle and timeouts – it’s the Switch operator.

    The Switch operator doesn’t work on IObservable<T> so most times you would never see it in intellisense.

    Instead it operates on IObservable<IObservable<T>> – a stream of observables – and it flattens the source to IObservable<T> by continually switching to the latest observable produced (and ignoring any values from the previous observables). It only completes when the outer observable completes and not the inner ones.

    This is exactly what you want – if a new value change occurs then ignore any previous results and only return the latest one.

    Here’s how to do it.

    First I removed the yucky event handling code into a couple of observables.

    var ones =
        Observable
            .FromEventPattern<
                RoutedPropertyChangedEventHandler<object>,
                RoutedPropertyChangedEventArgs<object>>(
                h => num_one.ValueChanged += h,
                h => num_one.ValueChanged -= h)
            .Select(ep => (decimal)ep.EventArgs.NewValue);
    
    var twos =
        Observable
            .FromEventPattern<
                RoutedPropertyChangedEventHandler<object>,
                RoutedPropertyChangedEventArgs<object>>(
                h => num_two.ValueChanged += h,
                h => num_two.ValueChanged -= h)
            .Select(ep => (decimal)ep.EventArgs.NewValue);
    

    Your code seems to be a bit muddled. I assume that the value of the DecimalUpDown controls are inputs to the server function that returns the result. So here are the functions that will call the server.

    Func<decimal, IObservable<decimal>> one2two = x =>
        Observable.Start(() =>
        {
            Thread.Sleep(300); // simulate work
            return x / 3.0m;
        });
    
    Func<decimal, IObservable<decimal>> two2one = x =>
        Observable.Start(() =>
        {
            Thread.Sleep(300); // simulate work
            return x * 3.0m;
        });
    

    Obviously you put in your actual server code calls in these two functions.

    Now it is almost trivial to wire up the final observables and subscriptions.

    ones
        .DistinctUntilChanged()
        .Select(x => one2two(x))
        .Switch()
        .Subscribe(x =>
        {
            Second = x;
        });
    
    twos
        .DistinctUntilChanged()
        .Select(x => two2one(x))
        .Switch()
        .Subscribe(x =>
        {
            First = x;
        });
    

    The DistinctUntilChanged makes sure we only make the call if the values actually changed.

    Then it’s easy to call the two server functions, perform the Switch and get back only the latest result which is then just assigned to the property.

    You may need to pop in a scheduler here or there and an ObserveOn to get the subscription over to the UI thread, but otherwise this solution should work nicely.

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

Sidebar

Related Questions

Have a simple contact us XPage created. Have server side validation in place that
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have data that has this kind of structure. Will be in ascending order by
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have had to write my first proper multithreaded coded recently, and realised just how
Have I understod the following right? font-family:sans-serif; Above will result in the default sans-serif
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them

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.