none
how to stop a chain of events RRS feed

  • Question

  • Hello

    If i have an eventhandler associated to a mousemouve, this will generate  a large number of mousemoveevents when the mouse makes a large move.

    Is there a way to stop all this events with one call?
    Monday, December 7, 2009 7:53 AM

All replies

  • Does setting MouseEventArgs.Headled to true as example below work for you?

            private void MouseMove(object sender, MouseEventArgs e)
            {
                e.Handled = true;
            }

    William
    Monday, December 7, 2009 8:41 AM
  • i think that that stop just one event

    i need to stop all the other event that has been raised


    Suppose that  a rapid mouse move raises 100 events

    for each event the controls has to do something that is not able to keep the pace with this large number of events


    so I was thinking of a way of cutting some of them

    somthing like to execute one event out of 20 for example when a large number is raised
    Monday, December 7, 2009 8:59 AM
  • Hi,

    you can remove the event handler first thing in the procedure, and add it again when the procedure finishes, like

    private sub OnMouseMove(sender, args)
    mysender = trycast(sender, SenderType)
    if mysender isnot nothing then
    RemoveHandler mysender.MouseMove, AddressOf OnMouseMove

    'Do whatever you must...

    AddHandler mysender.MouseMove, AddressOf OnMouseMove
    end if
    end sub
    http://wpfglue.wordpress.com
    Monday, December 7, 2009 12:37 PM
  • i do not want to remove the eventhandler

    i just need to find a way to execute one event out of n where n depends from the situations
    Friday, December 18, 2009 6:59 AM
  • Hi,

    hmmm... that's what I understood, therefore I suggested to register it again as soon as the routine finished whatever it has to do... Would this not work for you?
    http://wpfglue.wordpress.com
    Friday, December 18, 2009 11:20 AM
  • I would like to be able to see how many events are in the queue and decide which one to delete and which one to execute
    Friday, December 25, 2009 5:41 PM
  • Hi,

    When you move mouse than handler executes something. While executing event handler if you are moving mouse then no new events will be generated. You will recieve new event only when previous event handler is finishes its job. So no need to worry for new events.

    Or you can add Thread.Spinwait( ); in your handler so that you don,t recieve any new events between that period. But this is not a good idea. 

    Regard
    Alok
    Friday, December 25, 2009 8:04 PM
  • why it is not a good idea?
    Friday, December 25, 2009 8:32 PM
  • A small amount of spitwait can be helpful. Otherwise you are waisting processor time in doing nothing. And your app will also not be responding during that period.

    Saturday, December 26, 2009 5:17 AM
  • Hi,

    in this case, you could just copy the information from the EventArgs and put it into a queue, instead of processing it directly. Then a background worker thread could be monitoring this queue, decide which events to process and which to delete, and only do the lengthy job you mentioned for the ones that need it.

    So, you wouldn't disable the event handler, but only replace the long operation with a short one, that might trigger the long one later on another thread if needed.
    http://wpfglue.wordpress.com
    • Proposed as answer by Prettyman Saturday, December 26, 2009 10:35 PM
    Saturday, December 26, 2009 6:14 AM