Timers and loops
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Timers and loops
Dear friends, is there any way to get a timer to count even if a loop without a sysrefresh() inside it is running?
EMG
EMG
Re: Timers and loops
Enrico,
maybe a Solution :
Best Regards
Uwe
maybe a Solution :
Code: Select all
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)
Uwe
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
i work with FW.
If you have any questions about special functions, maybe i can help.
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Timers and loops
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
EMG
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Timers and loops
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
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
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Timers and loops
No, other apps don't stop. Maybe I can use threads but I'm not familiar with them.
EMG
EMG
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Timers and loops
Why don't you want to call sysrefresh()?
James
James
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Timers and loops
Because I already have tons of loops without SysRefresh().
EMG
EMG
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Timers and loops
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
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
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Timers and loops
Sorry, I see no differences at all in my PC. Maybe because I have a dual processor PC?
EMG
EMG
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Timers and loops
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
EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Timers and loops
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.
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.
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Timers and loops
Ok, I realize that I can't do what I had in my mind. No problem.
EMG
EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Timers and loops
Dear Enrico,
If you explain us what you have in your mind then we may try to help you
If you explain us what you have in your mind then we may try to help you
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Timers and loops
Easy to explain: I have tons of loops without SysRefresh() that use a waiting message for the user, something like this:
Now I would want to add something moving inside the function MsgBox() to give the user a better feel that the process is really going.
EMG
Code: Select all
MSGBOX( "Please wait..." )
WHILE ... // condition
// do a lot of work
ENDDO
CLOSE MSGBOX
EMG
Re: Timers and loops
Enrico,
maybe have a look at < Progres1.prg, Progtime.prg and Win32 > ?
Best Regards
Uwe
maybe have a look at < Progres1.prg, Progtime.prg and Win32 > ?
Best Regards
Uwe
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
i work with FW.
If you have any questions about special functions, maybe i can help.