LastInput.time is an Integer and m_idleTime is an Integer too. This line sometimes generates an Overflow exception, I think that this happens when both values are big negative values.
(Environment.TickCount - lastInput.time) > m_idleTime
How can I avoid that? With casting?
(CType(Environment.TickCount,Long) - CType(lastInput.time,Long)) > m_idleTime
Or maybe with this cast?
CType((Environment.TickCount - lastInput.time),Long) > m_idleTime
Thanks in advance.
EDIT: I'm using the GetLastInputInfo method to check how many time has been the computer idle. I have declared the return value from the call this way:
<StructLayout(LayoutKind.Sequential)> Public Structure StructLastInputInfo
<MarshalAs(UnmanagedType.U4)> Dim size As Integer
<MarshalAs(UnmanagedType.U4)> Dim time As Integer
End Structure
So I think that when the Environment.TickCount returns a negative value the same will happen with the GetLastInputInfo, right? But then the values of the substraction will be wrong because they will be negative, so as far as I see the problem what should be done is this:
Math.Abs(CType(Environment.TickCount, Long) - CType(lastInput.time, Long)) > m_idleTime
What do you think?