Dear friends, is there any way to get a timer to count even if a loop without a sysrefresh() inside it is running?
EMG
Dear friends, is there any way to get a timer to count even if a loop without a sysrefresh() inside it is running?
EMG

FUNCTION MAIN()
cTimeStart := Time()
i := 1
x := 0
FOR i := 1 to 12000000
x++
NEXT
cTimeEnd := Time()
MsgAlert( "Start : " + cTimeStart + CRLF + ;
"End : " + cTimeEnd + CRLF + ;
CRLF + ;
"Elapsed : " + TIME_DIFF( cTimeStart, cTimeEnd), "Elapsed Time ( 12000000-Counter )" )
RETURN NIL
// -----------------------------
FUNCTION TIME_COUNT(cTIME1,cTIME2)
local  nTIME1, nTIME2, nDELSECS, nHRS, nMINS, nSECS, nSECS1, nSECS2
nSECS1 Â := (val(substr(cTIME1,1,2)) * 3600) +;
       (val(substr(cTIME1,4,2)) * 60) + (val(substr(cTIME1,7)))
nSECS2 Â := (val(substr(cTIME2,1,2)) * 3600) +;
       (val(substr(cTIME2,4,2)) * 60) + (val(substr(cTIME2,7)))
nDELSECS := abs(nSECS2 - nSECS1)
nHRS Â Â := int(nDELSECS / 3600)
nMINS Â Â := int((nDELSECS - nHRS * 3600) / 60)
nSECS Â Â := nDELSECS - (nHRS * 3600) - (nMINS * 60)
RETURN right("00" + ltrim(str(nHRS)),2) + ":" + ;
right("00" + ltrim(str(nMINS)),2) + Â ":" + ;
right("00" + ltrim(str(nSECS)),2)Sorry, I was referring to a Windows timer (FWH's TTimer class): it stops counting when the program is in a loop without a call to SysRefresh() inside it.
EMG
Enrico,
I believe everything stops when there is no sysrefresh() inside a loop (other apps also). That is why you should put sysrefresh() inside any loop that takes more than a couple of seconds.
James
No, other apps don't stop. Maybe I can use threads but I'm not familiar with them.
EMG
Why don't you want to call sysrefresh()?
James
Because I already have tons of loops without SysRefresh(). ![]()
EMG
Enrico,
Well you say other apps are not affected, but that is not my experience. Trying running a continous loop without a sysrefresh():
do while .t.
endo
And then try running another app. It will be extremely sluggish since the loop is using 99% of the CPU time. Now try:
do while .t.
sysfresh()
enddo
And see the difference.
James
Sorry, I see no differences at all in my PC. Maybe because I have a dual processor PC?
EMG
Yes, it was that. If I run two empty loops then my system become sluggish too. Anyway, I don't really need to get the rest of the system responding fast during my waiting loops. I only need the timers going on with their work.
EMG
Enrico,
SysRefresh() lets Windows "breathe" and process its pending work ![]()
If for some reason you can't call SysRefresh() then you may need to run your timer action yourself. In example, you can use GetTickCount() to count time and every amount of ticks, call yourself the timer action. That would be an equivalent for receiving and processing a timer event.
Ok, I realize that I can't do what I had in my mind. No problem.
EMG
Dear Enrico,
If you explain us what you have in your mind then we may try to help you ![]()
MSGBOX( "Please wait..." )
WHILE ... // condition
// do a lot of work
ENDDO
CLOSE MSGBOX