システムが最後に起動されたのはいつかを知りたいです。
Environment.TickCount は機能しますが、int の制限により 48 ~ 49 日後に機能しなくなります。
これは私が使用しているコードです:
Environment.TickCount & Int32.MaxValue
long 型の return について何か知っている人はいますか?
これを使用して、システムのアイドル時間を把握しています。
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;
}