Hi José,
> As example, I change getsys to this:
>
> WHILE ( oGet:EXITState == GE_NOEXIT )
> nKey := Inkey( 600 )
> nKey := iif( nKey == 0, K_ESC, nKey )
> //nKey := WaitKey()
> GetApplyKey( oGet, nKey, lIsMouse)
> ENDDO
I am sure this can be done in several different ways. Your way will exit
the get after 600 seconds no matter if it is night or day. That may not
be appreciated by someone who comes back after sitting for an hour in a
meeting. The solution I use can be found below. It is the same I used in
Clipper (with NanFor) for many years.
> But need change another wait states too.
> In this way, I know when I can exit application.
That is what I meant with "a couple of other places" :-)
> Another way (until a final solution):
> using multithread, a thread to access disk every 5 minutes.
Or use the second thread to access the flag I mentioned ... but of
course, if the network drive is disconnected after only 5 minutes, it
might be a good workaround to access it from a second thread like that.
But it would probably be better to talk to the network admin.
Disconnecting drives that quickly is nuts and counterproductive, IMHO.
> Note:
> For backup, the best is application not in use, ok.
> But Harbour+ZIP works using shared DBFs.
Well, I prefer running a backup of the entire server on tape in the wee
hours. And some people use backup servers in a similar way. Just
different preferences :-)
Anyway, here is what I do. I have a function called LastKeySec()
//===========================================================
function LastKeySec( lSet )
// Save the seconds() value of the last keypress so TimeOutQuit() can
// determine if the applications is idle and can be terminated
static nLastKeySec := 0
if valtype( lSet ) != 'L'
lSet := .F.
endif
if lSet .or. nLastKeySec == 0
nLastKeySec := seconds() // Set the flag to "now"
endif
return nLastKeySec
//===========================================================
I simply call it with LastKeySec(.T.) from the getreader, from achoice()
user functions etc. It it easy to sprinkle a few of those function calls
where you need them. At the top of the application I call FT_OnTick()
like this:
FT_OnTick( { || TimeOutQuit( 79200, 18000, 3600 ) }, 1092.5 )
1092.5 is the number of hardware clock ticks in one minute. Real clock
ticks in Clipper, emulated clock ticks in Harbour. And below is
TimeOutQuit(). FT_OnTick() sets it up to be called every 60 seconds (the
1092.5 clock ticks).
//===========================================================
function TimeOutQuit( nFromSec, nToSec, nTimeoutSec )
// Quit the application at night if idle
//
// TimeOutQuit() terminates the application if the keyboard has been
// idle for more than <nTimeoutSec> seconds and the time is between
// <nFromSec> and <nToSec> seconds after midnight.
//
// For example: If <nFromSec> is 79200, <nToSec> is 18000 and
// <nTimeOutSec> is 3600 the application will quit if the time is
// between 22:00:00 and 05:00:00 and no key has been pressed in
// the last 60 minutes
local nSeconds := seconds()
local nLastKeySec := LastKeySec( .F. )
local nSinceLast, lQuit := .F.
nSinceLast := nSeconds - nLastKeySec
if nSinceLast < 0 // if <nLastKeySec> was set yesterday
nSinceLast += 86400 // Add 24 hours
endif
if nSinceLast > nTimeOutSec // The timeout period is over
if nToSec < nFromSec // The quitting period includes midnight
if nSeconds > nFromSec .or. nSeconds < nToSec
// We are between <nFromSec> and midnight or
// between midnight and <nToSec>
lQuit := .T.
endif
else // The quitting period does not include midnight
if nSeconds > nFromSec .and. nSeconds < nToSec
// We are between <nFromSec> and <nToSec>
lQuit := .T.
endif
endif
if lQuit
dbcloseall()
quit
endif
endif
return NIL
//===========================================================
Regards,
Klas