SugarBall

Sleep() problem!

19 posts in this topic

Hello guys, 

suddenly i'm having a problem with Sleep() func. When i give it less time like Sleep(2000), works, but when i tell it to sleep longer like Sleep(1000*60*3), it won't work... in fact is a surprise because it used to work perfectly.. anyone knows how to help?

SugarBall

Share this post


Link to post
Share on other sites



I doubt that its the multiplying but what happens if you try sleep(180000)?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

No, still doesn't works... pretty weird!!

Edited by SugarBall
definitive answer

Share this post


Link to post
Share on other sites

No, still doesn't works... pretty weird!!

Doesn't work means less than nothing to us, what doesn't work?

  • It doesn't sleep the script? 
  • the script didn't sleep as long as you're expecting?
  • the script sleeps longer than you're expecting?
  • the script crashes?
  • the script locks up?
  • the computer blue screens?
  • the computer catches on fire?

 Help us help you, give us more than "it doesn't work".

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

It doesnt sleep the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

No #requireAdmin and yes i am running compiled!....

it is the script of the AdLibRegister example... and i have changed the time to sleep longer... it used to work days before, and now no... no changes made at all...

If ProcessExists("SciTE.exe") = 0 Then
    MsgBox($MB_SYSTEMMODAL, "", "You will need SciTE.exe to be running for ConsoleWrite to display.")
EndIf

Example()

Func Example()
    
    AdlibRegister("MyAdLibFunc")

    
    Sleep(1000)   ;<<<<<<<<<<======================= IT WORKS BrewManNH

    
    MsgBox($MB_SYSTEMMODAL, "", "No console message(s) will be shown whilst the messagebox is displayed.")

    
    Sleep(180000) ; <<<<<<<======= my problem... it wont stop the script

    
    AdlibUnRegister("MyAdLibFunc")
EndFunc   

Func MyAdLibFunc()
    
    Local Static $iCount = 0
    $iCount += 1

    ConsoleWrite("MyAdLibFunc called " & $iCount & " time(s)" & @CRLF)
EndFunc

 

Edited by SugarBall

Share this post


Link to post
Share on other sites

I'd say it's something wrong or different on your computer, it works fine for me and for thousands of other people.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

No man it has nothing to do with my computer... try your logic a bit! 

It works for less time and in other scripts....why not specificlly there??

Edited by SugarBall

Share this post


Link to post
Share on other sites

As I said I, and thousands of other users, are not having any problems with the sleep function, or we would have heard something about it. You're an isolated case, you're having a problem no one else is complaining about, nor can we replicate the issue. So, logically, your computer or software on your computer, or something related to something you're doing is at fault and not AutoIt and/or the sleep function contained within it.

Asking us whether or not the function is working for us would be the logical question, not asking what is wrong with sleep (that no one else is experiencing). As far as we know, there's nothing wrong with the Sleep function, because it is working as intended for us.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ok guy....

your logic failed you again!

sure sleep function would work fine for everyone else, why wouldn't??

PS: try to read my comments completely and clearly

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Is your problem that "MyAdLibFunc" continues to be called and print to the console during the execution of "Sleep"?  If so, that is expected behavior.

Perhaps you want something more to the effect of this?

Func _WinAPI_Sleep($nMilliseconds)
    DllCall("Kernel32.dll", "NONE", "Sleep", "DWORD", $nMilliseconds)
EndFunc

 

Edited by Tekk

Share this post


Link to post
Share on other sites

As I said before, it's NOT happening for anyone else but you, regardless of the length of the sleep time. If it were we would have heard about it before this. My logic is not the issue, you are fixated on the idea that Sleep isn't working.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@BrewManNH

i know is happening only for me!

im not fixated with the idea that Sleep doesnt works, I AM HAVING A PROBLEM! 

lets drop this conversation if you cant help me!

 

@JohnOne

but why? that is what i thought in the first place..

Edited by SugarBall

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

As JohnOne said, Sleep is not really blocking (so it does not block an adlib registered function.

Instead, you can use a alternative like this :

AdlibRegister("MyAdLibFunc")

Sleep(2000)
_Sleep(2000)


Func MyAdLibFunc()
    Local Static $iCount = 0
    $iCount += 1

    ConsoleWrite("MyAdLibFunc called " & $iCount & " time(s)" & @CRLF)
EndFunc

Func _Sleep($iDelay)
    DllCall("Kernel32.dll", "none", "Sleep", "dword", $iDelay)
EndFunc

 

Edited by jguinch

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Sleep is a series of internal 10ms calls to the API jguinch posted above, exactly so it can be interrupted.

EDIT: unless the internal calls are 1000ms, that's the only reason I can see why

Sleep(1000)   ;<<<<<<<<<<======================= IT WORKS

would work, since the default time of adlib is 250ms

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Thank you very much both of you jguinch and JohnOne,

My imagination thought of something like your code jguinch o:)

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

  • Similar Content

    • ur
      By ur
      I have automated an install process by using the below code.
       
      Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc $win1 = "Text 1" $win2 = "Text 2" _WinWaitActivate($win1,"WARNING: This progra") Send("{ALTDOWN}n{ALTUP}");Send("{SPACE}") _WinWaitActivate($win1,"I DISAGREE and &do n") Send("{UP}n") _WinWaitActivate($win1,"Customer Information") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}{TAB}n") _WinWaitActivate($win1,"Click Next to instal") Send("{ALTDOWN}n{ALTUP}");Send("n") _WinWaitActivate($win1,"This feature require") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}n") _WinWaitActivate($win1,"Ready to Install the") Send("{ALTDOWN}i{ALTUP}");Send("i") _WinWaitActivate($win1,"The InstallShield Wi") Send("{ALTDOWN}f{ALTUP}");Send("f") _WinWaitActivate($win2,"You must restart you") Send("{ALTDOWN}n{ALTUP}");Send("n") Now if any new screen comes in the middle of installation, like some VC++ installation error or like that.
      The AutoIT is waiting in the background.
      Is there any way to skip the new screens with just "enter" and continue the installation??
    • InternetMonkeyBoy
      By InternetMonkeyBoy
      I'm going to build a new function that I have been unable to find.   PLEASE CORRECT ME.  It will tweak the internal AutoIt functions giving me the ability to trash stuff I do not want to spin around.  Get it?  Please throw me whatever you got and I will put it togeather.  Ship it now.
      My supersleep() will be in here somewhere.   It's on another thread.
    • quadrplax
      By quadrplax
      I have a light bulb which I can turn on and off using UDP commands (I already have that working in AutoIt). What I would like to do is run a script before the computer goes to sleep to turn it off, and after it resumes to turn it on. I've already got the latter working, but not the former. I tried Task Scheduler with the kernel power log, but the command doesn't get executed until the computer resumes from sleep. I've tried some things using WM_POWERBROADCAST, but so far I haven't got that to work either. Here's what I've got so far:
      Global Const $WM_POWERBROADCAST = 0x218 Global Const $PBT_APMSUSPEND = 0x4 Global Const $PBT_APMRESUMEAUTOMATIC = 0x12 While 1 Sleep(100) WEnd GUICreate("Event Receiver") GUIRegisterMsg($WM_POWERBROADCAST,"MY_WM_POWERBROADCAST") Func MY_WM_POWERBROADCAST($hWnd, $uMsg, $wParam, $lParam) Switch $wParam Case $PBT_APMSUSPEND MsgBox(0,"PBT_APMSUSPEND","PBT_APMSUSPEND"&@HOUR&@MIN&@SEC) Case $PBT_APMRESUMEAUTOMATIC MsgBox(0,"PBT_APMSUSPEND","PBT_APMRESUMEAUTOMATIC"&@HOUR&@MIN&@SEC) EndSwitch EndFunc Does anyone know how to make this work?
    • knucklesCZ
      By knucklesCZ
      Hello. I'd like to ask a question about AutoIt basics, as I was deeply thinking about creating a script, I got stuck at some questions such as:

      The Sleep function stops the script completely (it stops everything, if the script repeats an action every 5 seconds and there is a Sleep(1000), will it repeat once per 6 seconds in real time)?
      Can there be multiple loops working simultaneously depending on IFs or Switches? (loops controlling keyboard, deducing things from imagesearch etc.)
      If there can be multiple loops working in one moment (multiple actions), does Sleep stop the whole script or just one of the loops?

      Thanks for responses.
    • Keylonta
      By Keylonta
      When sleep is set to 500 and above it's causing the event that follows it to output 3 commands.
      In the following example the down keystroke is sent 3 times!
      Sleep(500)
      Send("{DOWN}",0)
       
      In the following example the down keystroke is sent once.
      Sleep(400)
      Send("{DOWN}",0)
      Why is it doing this? How do I stop sleep interfering with the event that follows it?