Timers and loops

User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Timers and loops

Post by Enrico Maria Giordano »

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

EMG
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Timers and loops

Post by ukoenig »

Enrico,

maybe a Solution :

Image

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)
 
Best Regards
Uwe :lol:
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.
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Timers and loops

Post by Enrico Maria Giordano »

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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Timers and loops

Post by James Bott »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Timers and loops

Post by Enrico Maria Giordano »

No, other apps don't stop. Maybe I can use threads but I'm not familiar with them.

EMG
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Timers and loops

Post by James Bott »

Why don't you want to call sysrefresh()?

James
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Timers and loops

Post by James Bott »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Timers and loops

Post by Enrico Maria Giordano »

Sorry, I see no differences at all in my PC. Maybe because I have a dual processor PC?

EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Timers and loops

Post by Enrico Maria Giordano »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Timers and loops

Post by Antonio Linares »

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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Timers and loops

Post by Antonio Linares »

Dear Enrico,

If you explain us what you have in your mind then we may try to help you :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Timers and loops

Post by Enrico Maria Giordano »

Easy to explain: I have tons of loops without SysRefresh() that use a waiting message for the user, something like this:

Code: Select all

MSGBOX( "Please wait..." )

WHILE ... // condition
    // do a lot of work
ENDDO

CLOSE MSGBOX
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
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Timers and loops

Post by ukoenig »

Enrico,

maybe have a look at < Progres1.prg, Progtime.prg and Win32 > ?

Best Regards
Uwe :lol:
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.
Post Reply