使用C#检索系统正常运行时间正常运行、检索系统、时间

由网友(寄 泩 蟲╮)分享简介:有没有一种简单的方法,使用C#来获取系统的正常运行时间?解决方案 公开时间跨度正常运行时间{得到 {使用(VAR运行时间=新的PerformanceCounter(系统,系统运行时间)){uptime.NextValue(); //读取它的值之前调用此额外的时间返回TimeSpan.FromSeconds(upti...

有没有一种简单的方法,使用C#来获取系统的正常运行时间?

解决方案

 公开时间跨度正常运行时间{
    得到 {
        使用(VAR运行时间=新的PerformanceCounter(系统,系统运行时间)){
            uptime.NextValue(); //读取它的值之前调用此额外的时间
            返回TimeSpan.FromSeconds(uptime.NextValue());
        }
    }
}
 

Is there a simple way to get a system's uptime using C#?

解决方案 电脑修复中出现oxc0000142是什么原因

public TimeSpan UpTime {
    get {
        using (var uptime = new PerformanceCounter("System", "System Up Time")) {
            uptime.NextValue();       //Call this an extra time before reading its value
            return TimeSpan.FromSeconds(uptime.NextValue());
        }
    }
}

阅读全文

相关推荐

最新文章