Page 1 of 1

system uptime?

Posted: Sat Jun 08, 2013 11:50 pm
by jassing
There are a bunch of ways to get the system uptime, but the ways I've uncovered, all seem to fail after a period (4 days, 2 weeks, where they just start over again)

I know that there is a finite limit to how high of a resolution can be used with a timer, but what's the best way?

I am writing to an sqlite database, involving mutexes and threads -- so the thread that gets the mutex, might not be "in order" -- so I need to be able to order them in a query so that they can be read in order.

Thanks
-j
(Windows-only, ok)

Re: system uptime?

Posted: Sun Jun 09, 2013 12:30 am
by Shield
GetTickCount64 if your system meets the requirements.

Re: system uptime?

Posted: Sun Jun 09, 2013 3:39 am
by Blankname
GetTickCount_() wrote:The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. To avoid this problem, use the GetTickCount64 function. Otherwise, check for an overflow condition when comparing times.
If you need a higher resolution timer, use a multimedia timer or a high-resolution timer.
Directly from MSDN.

Re: system uptime?

Posted: Sun Jun 09, 2013 4:18 am
by jassing
yup; knew that; but thanks.

Re: system uptime?

Posted: Sun Jun 09, 2013 5:43 am
by 136

Re: system uptime?

Posted: Wed Jun 12, 2013 11:09 pm
by em_uk
I posted this over there, so may as well post here as a more recent thread.

Code: Select all

Procedure.s UpTime() ; For XP or higher. Pretty much instant now :) ~ em_uk
  p=RunProgram("cmd.exe","/c net statistics workstation ","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
  If p
    While ProgramRunning(p) : o$+ReadProgramString(p)+#CRLF$ : Wend : CloseProgram(p)
    up$=Trim(Mid(o$,FindString(o$,"Statistics since",1)+16)) : up$=Left(up$,FindString(up$,#CRLF$,1)-1)
  EndIf
  ProcedureReturn up$
EndProcedure

Debug UpTime()