Esempio n. 1
0
        /// <summary>
        /// Get system idle time.
        /// </summary>
        /// <returns>Returns tick counts system has been idle in milliseconds.</returns>
        public uint GetIdleTime()
        {
            NativeMethods.LASTINPUTINFO lastInPut = new NativeMethods.LASTINPUTINFO();
            lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
            NativeMethods.GetLastInputInfo(ref lastInPut);

            return ((uint)Environment.TickCount - lastInPut.dwTime);
        }
Esempio n. 2
0
 /// <summary>
 /// Get system last input time.
 /// </summary>
 /// <returns>Returns system last input time.</returns>
 public long GetLastInputTime()
 {
     NativeMethods.LASTINPUTINFO lastInPut = new NativeMethods.LASTINPUTINFO();
     lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
     if (!NativeMethods.GetLastInputInfo(ref lastInPut))
     {
         throw new Exception(NativeMethods.GetLastError().ToString());
     }
     return lastInPut.dwTime;
 }