Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 2
    The first call to uptime.NextValue will return 0.
    – SLaks
    Commented Jun 9, 2009 at 20:12
  • 8
    What if counter name is localized? Commented Mar 5, 2013 at 0:44
  • 5
    Get localised names (2 = System, 674 = System Up Time) using: StringBuilder buffer = new StringBuilder(1024); uint buf_size = (uint)buffer.Capacity; Win32.PdhLookupPerfNameByIndex(null, id, buffer, ref buf_size); return buffer.ToString(); Commented Jul 24, 2013 at 0:41
  • 2
    I object that this is 'a simple way'. On top of it, try run it on *nix. Commented May 29, 2017 at 19:47
  • 1
    @Rbjz usually qualifying an answer with "using C#" means the OP is not looking for an answer that requires anything not already present in the .NET Framework. As of 2009 this was the simplest C# method for acquiring a non-overflowing "uptime" -- alternatives included querying WMI and scanning the System Event Log for a boot record.. and by comparison this method is the "simplest" and would work over all versions of Windows supported by .NET Not "using C#" requires PInvoke; GetTickCount64 (not in all Windows vers) or ZwQuerySystemInformation (undoc), or sysinfo (on posix+SVR4 systems)
    – wilson0x4d
    Commented Mar 11, 2018 at 22:15