.NET秒表待机/睡眠/休眠是否可识别?

Evg*_*nyt 15 .net stopwatch

System.Diagnostics.Stopwatch通过算计算机待机期间的时间?

Ali*_*tad 3

是的,它确实。

查看 Reflector 中的代码表明,如果不是Stopwatch.IsHighResolution,那么它将使用滴答计数(在我的环境中,该值是false所以它将使用DateTime.UtcNow.Ticks):

public void Start()
{
    if (!this.isRunning)
    {
        this.startTimeStamp = GetTimestamp();
        this.isRunning = true;
    }
}



public static long GetTimestamp()
{
    if (IsHighResolution)
    {
        long num = 0L;
        SafeNativeMethods.QueryPerformanceCounter(out num);
        return num;
    }
    return DateTime.UtcNow.Ticks;
}
Run Code Online (Sandbox Code Playgroud)