Event consuming

  • Thread starter Thread starter Joshua Moore
  • Start date Start date
J

Joshua Moore

I have a dotNet device (slow as tar) that is doing some really expensive
processes, and I need a way to handle the user clicking a button too
quickly, as I can't keep up with the redraw (1-2 seconds wait time per
click). I feel an event is the way to go, but don't know how to say "if the
event is in the process of being called as it is, stop, and get use the
latest data".

Thanks for dealing with newbies :)

Joshua Moore
 
I think the logic could be like this:

1) In event handler, set some class variable like "inEventProcessing" to
true at the beginning, doing some expensive operation, then set the same
class variable like "inEventProcessing" to false just before exiting event
handler.

2) When user clicks a button, you could check the above variable. If TRUE,
do not fire any event but instead let user know "he should wait for some
time before trying to click again". If FALSE, fire a new event so the above
method will be called again.
 
Joshua,
To prevent UI lockups, please consider using Thread for the time consuming
process in addition to what "Jiachuan Wang" recommended for
"inEventProcessing" class variable. Many CPU intensive processes just make
Form controls really sluggish in responsiveness.
That way you may even alter the priority of background process.

Fakher Halim
 
Dewiring the event handler during processing and then rewiring it at the
end is another approach that has been suggested:

private void MyEventHandler(object sender, EventArgs e) {
MyEvent -= new EventHandler(MyEventHandler);

// do your processing
.....

MyEvent += new EventHandler(MyEventHandler);
}

This can work better if your class will potentially be handling more
than one event at a time. For example you might want to allow the user
to make another request from a different part of the form.

Are you hourglassing the cursor during processing?

DC
 
Essentially it's using onClick to see if data is updated, if it is, then it
has to update several things. If the user clicks 5 times, if the event
handler sees that there are more events in the queue, to empty the queue
except the last, and only run the last event.
 
The user can press several different buttons, all doing the same
functionality minus the text of each button (minimal speed differences), and
they expect to wait until my verification comes back, so I don't want to
slow down the process waiting for threads to finish and check thread status.
I just want it to act like the Paint event where if it's supposed to repaint
5 times, it skips the first 4, and just does the last paint event, as all
the data is saved per used click. I'm currently setting up a event handler
and trying to dewire the event, but any help of a skeleton layout for what i
need, etc. would be greatly appreciated.

Thanks in advance, and to those already offering suggestions,
Josh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top