Created
February 15, 2016 12:10
-
-
Save WildGenie/327479a42b7ecc79282d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TimeSpan ts = TimeSpan.FromMilliseconds(Environment.TickCount); | |
Console.WriteLine("{0}d {1}h {2}m {3}s", ts.Days, ts.Hours, ts.Minutes, ts.Seconds); | |
//--------------------------- | |
using System.Diagnostics; | |
PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time"); | |
upTime.NextValue(); | |
TimeSpan ts = TimeSpan.FromSeconds(upTime.NextValue()); | |
Console.WriteLine("{0}d {1}h {2}m {3}s", ts.Days, ts.Hours, ts.Minutes, ts.Seconds); | |
//------------------------- | |
public TimeSpan UpTime { | |
get | |
{ | |
using (var uptime = new PerformanceCounter("System", "System Up Time")) | |
{ | |
uptime.NextValue(); // Must call extra time before reading its value | |
return TimeSpan.FromSeconds(uptime.NextValue()); | |
} | |
} | |
} | |
//--------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment