>I was thinking at a timer because in other ways you
>have to manage if the user quit the app killing it (with task manager i.e.)
>and not without 'normal' closing. Not really difficult to doA simple class as this:
DEFINE Class RunTimer as Line
tStart = {//}
cProtocol = "RunTimerTest.txt"
PROCEDURE INIT
This.tStart = dateTime()
This.LogTime(.T.)
ENDPROC
PROCEDURE DESTROY
This.LogTime(.F.)
ENDPROC
PROCEDURE LogTime(tlStart as Boolean) as Boolean
LOCAL lnSeconds, lcMins, lcSecs, lcText
if tlStart
This.Protocol("System started")
else
lnSeconds = round(dateTime() - This.tStart , 0)
lcMins = transform( int(lnSeconds/60) )
lcSecs = padl( mod(lnSeconds, 60), 2, "0" )
lcText = "System exited. UpTime: "+ lcMins +":"+ lcSecs
This.Protocol(lcText)
endif
ENDPROC
PROCEDURE PROTOCOL(tcText as String) as Boolean
LOCAL llRetVal
tcText = iif(vartype(tcText)="C", tcText, "No text supplied")
llRetVal = StrToFile(transform(datetime())+ space(4)+ tcText + chr(13)+ chr(10), This.cProtocol, .T.) > 0
return llRetVal
ENDPROC
ENDDEFINE
can be called upon StartUp of the application like this
public goLogTime
goLogTime = NewObject("RunTimer", "PROGRAM\Test_LogTimer.PRG")
There's nothing more that has to be done. The LogTimer takes care of himself.
On my machine works perfectly well, even with CTRL+ALT+DEL and "Quit task"
Additionally I might have to address the fact that a user could probably
have the application running in a second task. This should not result in
double counting the UpTime.
>>If you think at how many cookies, temp files, ecc. we got in our pc at a day,
>don't feel bad to add few bytes to preserve your copyright.That is absolutlely true. However I remember when I came back from school
telling my father about my bad grades, he was not too happy. So I said
"but there are three others that also have such a bad one, and even worse".
He said "I'm not interested in the others, don't use bad examples as an
excuse for You own misbehaviour" - something like that. So, Yes other people's
systems won't break down if I add a little more junk to their disk, but if there
is a better solution, I'd choose that.