Is WPF MouseButtonEventArgs timestamp value negative?

I have code for a WPF trigger that checks for double clicks:

private void HandleButtonUp(object sender, MouseButtonEventArgs mouseEventArgs) { if (mouseEventArgs.ChangedButton == MouseButton.Left && (mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime) { this.InvokeActions(mouseEventArgs); _lastClick = 0; // Require 2 clicks again } else _lastClick = mouseEventArgs.Timestamp; } 

It has worked so far. But today, suddenly, a single click causes an action. When I checked the code, I found that the timestamp value is negative, which leads to the fact that it is always less than SystemInfo.DoubleClickTime (500 is what mine is set to).

This is normal? Why has this suddenly changed?

+6
source share
1 answer

The InputEventArgs.Timestamp property behaves like an Environment.TickCount , where you can find the following notes:

The value of this property is inferred from the system timer and stored as a 32-bit signed integer. Therefore, if the system runs continuously, TickCount will increase from zero to Int32.MaxValue for about 24.9 days, then go to Int32.MinValue, which is a negative number, then increment back to zero over the next 24.9 days.

TickCount differs from the Ticks property, which is the number of 100-nanosecond intervals that have passed since 01.01.00, 12:00.

Use the DateTime.Now property to get the current local date and time on this computer.

Ignoring the rare case when a jump occurs (after 24.9 days, and then every 49.7 days), you can check the following:

 Math.Abs(mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime 
+10
source

Source: https://habr.com/ru/post/950183/


All Articles