我想知道最后一次启动系统是什么时候。
Environment.TickCount 可以工作,但由于 int 的限制,它会在 48-49 天后中断。
这是我一直在使用的代码:
Environment.TickCount & Int32.MaxValue
有谁知道长类型返回以某种方式?
我正在使用它来了解系统的空闲时间:
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;
}