Skip to main content

Timeline for Retrieve system uptime using C#

Current License: CC BY-SA 2.5

8 events
when toggle format what by license comment
Jul 31, 2019 at 21:08 comment added Guido Kleijer This function does not return the Uptime, it returns the duration between last restart and now. Turning the computer on and of does not affect this behaviour.
Mar 11, 2018 at 22:15 comment added wilson0x4d @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)
May 29, 2017 at 19:47 comment added Robert Cutajar I object that this is 'a simple way'. On top of it, try run it on *nix.
Jul 24, 2013 at 0:41 comment added Oliver Bock 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();
Mar 5, 2013 at 0:44 comment added abatishchev What if counter name is localized?
Jun 9, 2009 at 20:34 vote accept ProgrammingPope
Jun 9, 2009 at 20:12 comment added SLaks The first call to uptime.NextValue will return 0.
Jun 9, 2009 at 19:58 history answered SLaks CC BY-SA 2.5