WhatTypo Posted September 3, 2010 Posted September 3, 2010 Are there any Functions that Delay or Pause other than the Sleep() Function? The Sleep() Function pauses the entire script for that duration. I am looking for a way to put a pause in one section of my code that will continue to allow the rest of the program to execute during that pause. For example if Loop1 and Loop2 were being executed at the same time, how could I put a pause in Loop1 that will allow Loop2 to continue execution without being paused at the same time?
BrewManNH Posted September 3, 2010 Posted September 3, 2010 This is what I use to delay executing the code inside the If....EndIf. The way this is written, the part marked as <your code goes here> only gets executed every 1 second. If the $DelayTime hasn't gotten to the right point yet, then it just returns from the function.$Timer = TimerInit() Func SomeFunction $Delay = TimerDiff($Timer) $DelayTime = (1000) If $Delay > $DelayTime Then <your code goes here> $Timer = TimerInit() EndIf EndFunc 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 GudeHow 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
enaiman Posted September 3, 2010 Posted September 3, 2010 (edited) Loop1 and Loop2 were being executed at the same timeI'm really curious how do you manage to execute two loops at the same time? Are you using AdLib? I'm pretty sure multi-threading is not possible in AutoIt so you can't possibly have 2 loops executing at the same time.Maybe a bit of code would help understand what you really want. Edited September 3, 2010 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
WhatTypo Posted September 3, 2010 Author Posted September 3, 2010 Thanks I am going to play with using the general idea in a while loop. What I am trying to do is make a basic timer. What I tried first was basically $Timer1 = 1 Sleep (5000) $Timer1 = 0 then in another function I was trying to do If $Timer1 = 1 Then ; do one thing ElseIf ; do another The goal was to flag whether an action had been performed within the last 5 seconds or not. Of course the Sleep() function paused the entire program rather than just waiting before proceeding to the next line
WhatTypo Posted September 3, 2010 Author Posted September 3, 2010 I'm really curious how do you manage to execute two loops at the same time? Are you using AdLib? I'm pretty sure multi-threading is not possible in AutoIt so you can't possibly have 2 loops executing at the same time.Maybe a bit of code would help understand what you really want.The functions were initialized with HotKeySet(). if 2 functions are ran from different hotkeys they seem to play without interrupting each other.
WhatTypo Posted September 3, 2010 Author Posted September 3, 2010 The functions were initialized with HotKeySet(). if 2 functions are ran from different hotkeys they seem to play without interrupting each other.I could have been totally wrong about that but that is how it appeared to me. I am not totally sure that it is actually working that way I think the other functions I was using with other hotkeys may have just been so short that I didn't notice it pause to run them before continuing the function that was running when I pressed the second hotkey. I don't believe it is possible to have 2 functions execute simultaneously I think it just pauses the first and resumes when the 2nd hotkey's function is finished
WhatTypo Posted September 3, 2010 Author Posted September 3, 2010 BrewManNH I just wanted to say thank you. I got my stuff working that I was trying to do. You gave me some ideas on how to do it without needing a 2nd function. I appreciate the tip it was quite helpful. This is what I use to delay executing the code inside the If....EndIf. The way this is written, the part marked as <your code goes here> only gets executed every 1 second. If the $DelayTime hasn't gotten to the right point yet, then it just returns from the function. $Timer = TimerInit() Func SomeFunction $Delay = TimerDiff($Timer) $DelayTime = (1000) If $Delay > $DelayTime Then <your code goes here> $Timer = TimerInit() EndIf EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now