Sign in to follow this  
Followers 0
socap

Sleep till 2 minutes on clock pass.

9 posts in this topic

Sleep(2 * 59.1 * 1000)

Next

I can't make next every 2 minutes precisely

Help please, instead of this sleep, sleep it sleeps for two minutes of earth time.

I mean it should sleep till 2 minutes on clock pass.

Share this post


Link to post
Share on other sites



socap,

This is the routine that I use.

#include <date.au3>

Local $stime = _nowcalc(), $i = 0

While $i < 2
    Sleep(1000) ; sleep for a sec
    $i  = _datediff('n',$stime,_nowcalc())
wend

Good Luck!

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Sleep((60000 * 2) - (@SEC * 1000))


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

I've once made a clock that would update the display every second. I used sleep this way:

While True
    UpdateDisplay()
    ; Wait until next second pass
    Sleep(1000-@MSEC)
WEnd

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

or maybe something more complicated currently set to react on every second (func taken from monoceres example on 'Sleep down to 100 Nano seconds')

but as Jos pointed @Min is probably what OP need

$hDll=DllOpen("ntdll.dll")
$hStruct=DllStructCreate("int64 time;")
$s = @SEC
Do
    DllStructSetData($hStruct,"time",-1*(1*10))
    DllCall($hDll,"dword","ZwDelayExecution","int",0,"ptr",DllStructGetPtr($hStruct))
Until $s <> @SEC
$a = TimerInit()
For $x = 1 To 100
    Do
        DllStructSetData($hStruct,"time",-1*(1*10))
        DllCall($hDll,"dword","ZwDelayExecution","int",0,"ptr",DllStructGetPtr($hStruct))
        $t = TimerDiff($a)
    Until $t > 1000*$x
    ConsoleWrite($t&' Sec = '&@SEC&@CRLF)
Next
DllClose($hDll)
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

@ripdad,

is

Sleep((60000 * 2) - (@SEC * 1000))
the same as
sleep(120-@sec)
neither of which will work in a loop unless you use a variable that is decreased with each iteration.

@jos,

I see @min used frequently. Do you not get less than 1 full minute though, depending on when the @min macro is invoked? And there is the problem of crossing an hour boundry.

Just my 2 cents, gentlemen.

Happy New Year,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well, I suppose it's a matter of interpretation of the OP, which I could have misinterpreted.

It appears, with the given information of the OP, that he wants to pause a For Loop for 2 minutes

to the top of that 2 minutes (real clock time), which would be 2:00, for instance.

I could be wrong.

This...

Sleep((60000 * 2) - (@SEC * 1000))

Sleeps for 2 minutes minus the spent clock seconds of that 2 minutes.

Which becomes apparent at 2:00.

and this ...

Sleep(120-@sec)

Sleeps for 120 milliseconds minus the spent clock seconds?

Max number for @SEC is 59. Some additional math would be needed, I think.

And a Happy New Year to you too and to all the AutoIt Community!

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

ripdad,

You are right, my mistake!

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0