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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:07:36+00:00 2026-06-18T03:07:36+00:00

I’m new to RX but feel it should be able to provide a good

  • 0

I’m new to RX but feel it should be able to provide a good solution to a task I wish to solve. After quite a bit of searching I still haven’t found a solution.

I have a WPF application within which a control does some work in response to some mouse move events. I would like to reduce the frequency of the events, so that the handler gets called less frequently than is currently the case (as the user moves the mouse across the control). Ideally, what I want is to set up and subscribe to an observer. The observer should observe the mouse move events and call the client code with the most recent event and arguments after a particular time window has elapsed, say 0.2s. Being new to RX, I first replaced my original standard event hook-up with an observer as follows:

var mouseMove = Observable.FromEventPattern<MouseEventArgs>(myControl, "MouseMove");

mouseMove.Subscribe(args => myControl_MouseMove(args.Sender, args.EventArgs)); 

This seemed to work fine.

I then attempted to modify the observer to get the behaviour I described above. I tried using the Throttle() call and the Sample() call. These didn’t produce the outcome I expected (or desire). In fact in certain cases using a particular overload of the Throttle/TimeSpan call killed my application dead, which still I don’t understand.

This is an example of what I’ve tried:

var mouseMove = Observable.FromEventPattern<MouseEventArgs>(myControl, "MouseMove").Throttle(TimeSpan.FromSeconds(0.2));

mouseMove.Subscribe(args => myControl_MouseMove(args.Sender, args.EventArgs)); 

From reading, Throttle appears to swallow events until the frequency drops below a particular threshold (not quite what I expected), whereas I believe Sample samples the observed events at a regular interval? I would like the client code to be given the most recent event in a given time interval. If no events have been recorded in that interval, then the client should not be called.

Hope someone can help an RX newbie on this.

Oh, I also want to be kept informed of the (reduced frequency) mouse moves for the duration of the control’s lifetime.

Max

  • 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-18T03:07:37+00:00Added an answer on June 18, 2026 at 3:07 am

    I think you’re on the right track with Sample – what, specifically, did this not do for you?

    Example LINQPad snippet:

    void Main()
    {
        var window = new Window();
        window.Content = ctrl;
        window.Show();
        var mouseMove = Observable
            .FromEventPattern<MouseEventArgs>(window, "MouseMove")
            .Sample(TimeSpan.FromSeconds(0.2));
        var disp = mouseMove.Subscribe(args => myControl_MouseMove(args.Sender, args.EventArgs));     
        window.Closed += (o,e) => disp.Dispose();
    }
    
    ItemsControl ctrl = new ItemsControl();
    
    // Define other methods and classes here
    private void myControl_MouseMove(object sender, MouseEventArgs args)
    {
        ctrl.Dispatcher.BeginInvoke((Action)(() => {ctrl.Items.Add(args.GetPosition(ctrl));}));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when 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.