1

I have been using this for long time but now I have found the bug that after 48 days it dos not give me the right idle time.

It is due to the integer32 bits. I could manage to get the tick counter in long through Environment.TickCount is not enough

However, my need is to get the idletime and GetLastInputTime() [http://www.codeproject.com/KB/system/rtwidledll.aspx?display=PrintAll] is not returning me long.

public static int GetIdleTime()
{
    return (Environment.TickCount & Int32.MaxValue)- (int)GetLastInputTime();
}

/// <summary>
/// Get the last input time from the input devices.
/// Exception: 
/// If it cannot get the last input information then it throws an exception with 
/// the appropriate message.
/// </summary>
/// <returns>Last input time in milliseconds.</returns>
public static uint GetLastInputTime()
{
    LastInputInfo lastInPut = new LastInputInfo();
    lastInPut.BlockSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
    if (!GetLastInputInfo(ref lastInPut))
    {
        throw new Exception(GetLastError().ToString());
    }

    return lastInPut.Time;
}
Community
  • 1
  • 1
codebased
  • 6,945
  • 9
  • 50
  • 84
  • 1
    You have to measure more than 49 days of idle time? Does anything at http://jeff.bovine.net/Terminal_Services_idle_time help? – Gabe Jan 11 '11 at 00:22

0 Answers0