■ PerformanceCounter 클래스의 NextValue 메소드를 사용해 PC 사용 시간을 구하는 방법을 보여준다.
▶ PerformanceCounter 클래스 : NextValue 메소드를 사용해 PC 사용 시간 구하기 예제 (C#)
1 2 3 4 5 6 7 |
using System; TimeSpan timeSpan = GetPCUsageTime(); Console.WriteLine(timeSpan); |
※ 본인 PC에서 실행한 결과 2.00:20:43.6880000가 출력되었는데 실제 사용한 시간은 20분 정도였다…
▶ PerformanceCounter 클래스 : NextValue 메소드를 사용해 PC 사용 시간 구하기 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
using System; using System.Diagnostics; #region PC 사용 시간 구하기 - GetPCUsageTime() /// <summary> /// PC 사용 시간 구하기 /// </summary> /// <returns>PC 사용 시간</returns> public TimeSpan GetPCUsageTime() { using(PerformanceCounter performanceCounter = new PerformanceCounter("System", "System Up Time")) { performanceCounter.NextValue(); return TimeSpan.FromSeconds(performanceCounter.NextValue()); } } #endregion |