Timers and loops

Timers and loops

Postby Enrico Maria Giordano » Thu Feb 04, 2010 4:33 pm

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

Re: Timers and loops

Postby ukoenig » Thu Feb 04, 2010 5:59 pm

Enrico,

maybe a Solution :

Image

Code: Select all  Expand view  RUN

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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Timers and loops

Postby Enrico Maria Giordano » Thu Feb 04, 2010 8:47 pm

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

Re: Timers and loops

Postby James Bott » Thu Feb 04, 2010 10:23 pm

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

Re: Timers and loops

Postby Enrico Maria Giordano » Thu Feb 04, 2010 10:31 pm

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

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

Re: Timers and loops

Postby James Bott » Thu Feb 04, 2010 10:45 pm

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

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

Re: Timers and loops

Postby Enrico Maria Giordano » Thu Feb 04, 2010 11:06 pm

Because I already have tons of loops without SysRefresh(). :-)

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

Re: Timers and loops

Postby James Bott » Thu Feb 04, 2010 11:21 pm

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

Re: Timers and loops

Postby Enrico Maria Giordano » Fri Feb 05, 2010 7:49 am

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: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Timers and loops

Postby Enrico Maria Giordano » Fri Feb 05, 2010 7:55 am

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

Re: Timers and loops

Postby Antonio Linares » Fri Feb 05, 2010 8:56 am

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: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Timers and loops

Postby Enrico Maria Giordano » Fri Feb 05, 2010 9:06 am

Ok, I realize that I can't do what I had in my mind. No problem.

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

Re: Timers and loops

Postby Antonio Linares » Fri Feb 05, 2010 9:15 am

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

Re: Timers and loops

Postby Enrico Maria Giordano » Fri Feb 05, 2010 9:42 am

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

Code: Select all  Expand view  RUN
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
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Timers and loops

Postby ukoenig » Fri Feb 05, 2010 10:50 am

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 57 guests