MouseUp event fired again several minutes after the button was pressed - winforms

.NET CF WinForms app runs on Windows CE5 and CE7 devices, with touchscreen.
We hook up to MouseUp event rather than Click in our Button implementation (because of apparent problems with touchscreen sensitivity).
We also hook up a Windows Message filter on application message queue, and filter out MouseDown and/or MouseUp messages based on certain conditions (e.g. screen backlight is off). Normally messages are let through.
Another thing to note - all screens in the application are implemented as controls, and kept in memory forever, just sent to the background. We use OpenNETCF Button2 and Application2.
Now there's a very strange problem, where particular button event handlers get "stuck": event is fired when button is pressed, as expected, but then again after a random time interval - sometimes 20-30 minutes after!
There would be screen interaction in the meanwhile, user presses other buttons, the original screen control and the button become invisible, and then suddenly - typically on next screen touch - the same MouseUp handler for this button is fired again, and then keeps firing.
It also seems to happen with different buttons in the same, certain position on the screen, not each and every button.
The primary question here is - how on earth can an event (MouseUp message for this particular control?) get stored somewhere, and then activated/sent again some time after?
Control is invisible by the time, so it can't be physical touch, presumably.

Related

BindingNavigator events not raised

I have an "odd" situation.
I've got a form with a binding source and a binding navigator.
In this instance, I've got 161 records (via EF6) to display.
The databinding to the controls works nicely.
But what I find is that the expected events for the binding navigator don't happen consistently. Then they settle down.
I've got event handlers (additional to the default ones, but the same thing happens when I remove the default ones as well)
I set the binding source one the navigator, and the "Position Changed" event is raised (as I'd expect)
Clicking on any of the "Move" buttons, or editing the position field will result in:
No event being raised (not the item click events, not the binding source Position Changed) roughly 3 out of 4 times.
Then the event raises, all the expected navigation occurs, and repeat.
But it doesn't seem to be permanent, because after a while almost all the records have the navigation all starts working properly.
This happens with and without the debugger connected.
The other thing I notice is that when it fails, the icon in the taskbar flashes once.
It's not something in any of my handler code, because it never gets to my code.
It might be a property setting.
It's not an exception, because even with "break on all exceptions", no exception is reported.
When you talk about "move" buttons, I take it that you mean the next/previous record navigation buttons on the BindingNavigator. Those buttons are not full-fledged Windows controls, but rather they are "lightweight" controls. I've seen issues in the past because of this.
While I do not have all the details fresh in memory, it had to do with the fact that they don't steal the focus away from other controls as regular Windows controls do, and this caused some events to not be raised.
I suggest you create your own navigation buttons, which is what I ended up doing on all my Windows Forms project. Those regular buttons can then call the BindingSource methods such as MoveNext and so on.

When does each event occur in WinForms

As I am trying to make my own custom "WinForms", I am left confused on when does each mouse event occurs. I have made my own custom classes, but now the events are something I have to rework, as they won't work right.
I have a custom class for controls. Objects from that class can contain other controls, which can contain other controls and so on. There is a main control, which gets input from a picture box. That input is what is where the mouse is and what even has been activated in the picture box.
So far I have figured, that MouseMove, MouseHover and MouseDown events are the simplest to write, as they occur in simple conditions. But the rest require additional data about the mouse's location, state and past. MouseDoubleClick seems to activate after a specific sequence of events (strictly down-up-down-up, down-up-down-move-up and down-up-down-move-leave-enter-move-up, with the movement events not activating). With that in mind, I am even more confused.
In what conditions and sequences does each mouse event occur?
EDIT
Further testing made things even more confusing. For one, now I want to know at what rate is the MouseMove being registered, and testing it shows that between each event there is a different time (or so does my use of a StopWatch say). This is important, because then that raises the question when is Hover being triggered.
Click is down-up, where moving is allowed between the two.
DoubleClick proved to be simple enough - down-up-down-up, where moving is allowed explicitly only between the second down-up.
Hover activates only once after each Enter, when the mouse remains stationary; if you want to trigger Hover again, the mouse has to leave and then re-enter.
So the question now is how the system tracks the mouse's activity - how does it detect the mouse moving, being held down and being released. Hopefully that would help me get the full answer.

WPF's command firing twice on fast doubleclick

From a production application, we notice that our WPF buttons fire the ICommand.Execute method twice on fast double click.
Now, on every Command, the application is covered with a full-screen spinner animation, preventing any further interaction with the application.
This github repo contains a minimalistic repro of the issue. Note that:
when the Button's Command fires, the "IsBusy" flag is set to true
as a consequence, the BusyIndicator overlay will be shown
as a consequence, the Button cannot be pressed again until after 300ms
However, especially on slow computers, when fast double-clicking (really fast, like gaming fast that is), it is possible to fire the command twice without the BusyIndicator blocking the second call (this can be seen if the output shows 2 'click' lines right after one another).
This is unexpected behavior to me, as the IsBusy flag is set to true right away on the UI thread.
How come a second click is able to pass through?
I would expect the IsBusy Binding to show the overlay on the UI thread, blocking any further interaction?
The github sample also contains 2 workarounds:
using the ICommand.CanExecute to block the Execute handler
using the PreviewMouseDown to prevent double clicks
I'm trying to understand what the issue is.
What work-around would you prefer?
Diagnosis
This is only my guess and not a solid and confirmed info, but it seems that when you click the mouse button, the hit-testing is done immediately, but all the mouse related events are only scheduled to be raised (using the Dispatcher I presume). The important thing is that the control that is clicked is determined at the time the click occurred, and not after the previous click has been completely handled (including all UI changes that potentially follow).
So in your case, even if the first click results in showing the BusyIndicator covering (and thus blocking) the Button, if you manage to click for the second time before the BusyIndicator is actually shown (and that does not happen immediately), the click event on the Button will be scheduled to be raised (which will happen after the BusyIndicator is shown), causing the command to be executed again even though at that point the BusyIndicator will possibly be blocking the Button.
Solution
If your goal is to prevent command execution while the previous one is still executing the obvious choice is to make the Command.CanExecute result depend on the state of the IsBusy flag. Moreover, I wouldn't even call it a workaround, but a proper design.
What you're facing here is a clear-cut example of why you shouldn't make your business logic rely on UI. Firstly, because rendering strongly depends on the machine's processing power, and secondly because covering a button with another control by far does not guarantee the button cannot be "clicked" (using for example UI Automation framework).

What event or events are fired when on appearance of alarms, reminders, or phone call notifications?

I'm working on a WP Silverlight game with a timer, and so need to pause the game whenever something happens to take focus away from the app. However, the PhoneApplicationService events don't fire when alarms or reminders appear on the screen, nor when phone calls arrive.
I tried overriding OnGotFocus/OnLostFocus on the page used for the game screen, but they aren't called either when a reminder/alarm dialog appears. Which brings us back to my question -- what events or overrides will let me know when alarms, reminders or calls have taken focus so I can pause my game appropriately?
I believe it's the Obscured event - see this forum post and this one as well.

Click event dispatches to wrong control

We have the requirement that on some undeterministicly fired hardware events, depending on the event, the GUI changes. Due to the GUI cmnplexity this may take a few seconds.
Now the problem. If I click on a button while GUI is still busy sometimes the wrong button is invoked because after GUI layouting this button is now at the mouse coordinates where the click occured before.
Iam sure with Windows Forms the behaviour was different. Can I get around this behaviour?
You can :
Hide or cover the UI when it is refreshing (with a Busy Indicator for example)
Optimize the refresh (see MSDN Wpf Optimization category, especially Layout and design)
The quick and dirty - store a IsRefreshing variable and use it to diable the buttons or cancel your buttons handlers
EDIT
The real question is : what is your bottleneck ? the UI refresh or the logic behind ?

Resources