I want to check user inactivity in my application. I did a bit of work and went to use GetLastInputInfo and Environment.TickCount, because it seemed very simple. Unfortunately, this turns out to be a little touching.
GetLastInputInfo returns a LASTINPUTINFO structure that has the last TickCount value as DWORD (i.e., UInt32). Theoretically, I want to subtract this value from Environment.TickCount, and this gives me how many ms the user was inactive.
Environment.TickCount returns Int32. Both will turn around when they reach their maximum value, which is different for Int32 and UInt32. I'm a little uncomfortable with this, especially because the code essentially cannot be tested (Environment.TickCount wraps up after 24.9 days, and the function is before it).
Here is what I have done so far:
[DllImport("user32.dll")] static extern bool GetLastInputInfo(out LastInputInfo plii); struct LastInputInfo { public uint cbSize; public uint dwTime; }
Is there a simple enough way to handle wrappers or use a different approach to completely detect user inaction? Any advice on how to test this without a computer dedication for 25 days is also welcome.
source share