Sign in to follow this  
Followers 0
imNew

Help Please: How to Pause a script? (not like "while NOT $paused)

12 posts in this topic

#1 ·  Posted (edited)

Hello all, I need a method to pause a running script. my current method is go find the autoit icon in tast bar (the place with a clock and volumn settings and stuff) and click on it.

I can not possibly use variables like "$paused = false; while Not $paused" sytax to do so, since my program involves too many loops and loops within loops, and long loops you have to wait a while until if finish one iteration. I m looking for someting similar to "Exit()", the closest I can get is "processWait()", but not sure how to make use of it.

any help would be much appreciated, thanks

Edited by moxinghbian

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Not sure why it wouldn't work....

Hotkeyset("a","Pause")

Func Pause()

$Paused = Not $Paused

While $Paused

Sleep(100)

Wend

Endfunc

Have you tried it? It should work...

Thank you DarkShadow, it does work for some cases. but I had problem with it, if I m inside a long loop, that script doesn't seem to pause at all =/

actually I m not quite sure what will happen if the program is in a loop, then I start another parallel loop with it. I heard autoit is not built for multi-threading

Edited by moxinghbian

Share this post


Link to post
Share on other sites

errr, about posting the code I m working on. that would be hard to do, since it's more of a general question.

my programs consist of a lot of loops one after another. thus my programs are always looping. the GUI loop and the do_stuff loop.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

That shouldn't stop it from working.... What exactly does the script do? Regardless of what it does, it should still pause it, unless possibly if it's in the middle of doing something (like maybe writing a file or some single command that isn't really instant.)

Edit:

Hotkeyset("a","Pause")

Hotkeyset("s","Resume")

Func Pause()

While 1

Sleep(100)

Wend

Endfunc

Func Resume()

Sleep(1)

Endfunc

Edited by darkshadow791

Share this post


Link to post
Share on other sites

errr, about posting the code I m working on. that would be hard to do, since it's more of a general question.

my programs consist of a lot of loops one after another. thus my programs are always looping. the GUI loop and the do_stuff loop.

Imagine... A Newbie with "1" post

You know... I wasn't going to post here... but

Either

1. You are given a free language - AutoIt

2. You are given a free editor - SciTE

3. You are posting on a free board - AutoIt Forums

4. You are given free support - by AutoIt Proficient People

5. You can use free programs already made in - Example Scripts

6. I am positive there are...

A. Better free scripts, than the one you need help with

B. Located on this board

C. All open source

D. With support for the asking

E. Some with skins and more

.... and you think you have something we would want to steal ?

( or maybe you have something to hide... Malware possibly??? )

Think Again!

You should be Thanking Everyone!

OR

Your loops are so bad the script is ruined...

if so, we can't help you anyway!

BTW

Welcome to the forums

8)

Rant:off


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks for the replies, but I don't think I m able to post my loops in here, they are mostly 200-400 lines long, mostly deal with pictures on a screen. I have to handle all the possible cases and exceptions, that's why those loops are long. my program eventually has 4-5 of those loops and one big while(1) loop wrap around it.

besides that, I will just ask some more general questions: when I execute Sleep() func, what will happen?

I provided some pseudo code below:

;================

Hotkeyset("a","Pause")

Hotkeyset("s","Resume")

Func Pause()

While 1

Sleep(100)

Wend

Endfunc

Func Resume()

Sleep(1)

Endfunc

;================

;first of all, we have the GUI loop running all the time

while 1

sleep(1000)

wend

; then an interruput happened:

Hotkeyset("`","interrupt")

Func interrupt()

while not $done

do_stuff()

$done = check_IfDone_is_true()

wend

endfunc

func do_stuff()

for $i = 0 to 100

;lots of things happen in here

sleep(100)

next

endfunc

func check_IfDone_is_true()

while $some_condition

;some if/else here to update $done

wend

endfunc

so, assumming my script is looping inside do_stuff. what will happen if I call the Pause() function?

Share this post


Link to post
Share on other sites

Try a " [ codebox ] [ /codebox ] ", we can scroll through 400 or so lines of code, if you dont show us the script how can we possibly help?


tolle indicium

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

my func's are scattered all over different files hard to patch them together to post a working script here,

but I will make a running program to represent the problem fast. it is a counter.

my question is a very simple one I think.

it's just how sleep() works. it will pause everything that is running in a script, except for interrupts right?

thus, as long as i do not cause interruptions in other loops the Pause() will work?

CODE

#include <GuiConstants.au3>

opt("guioneventmode", 1)

$GUI_name = "TEST"

$main = GuiCreate($GUI_name, 104, 103,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

WinMove($GUI_name, "", 1030,700)

;rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

;CLOSE routine

;rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

HotKeySet("{ESC}", "CLOSE_Clicked");

HotKeySet("`", "test");

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE_Clicked")

Func CLOSE_Clicked()

Exit

EndFunc

;rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

;Display routine

;rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

$display = GuiCtrlCreateLabel("", 0, 0, 100, 45)

$display1 = GuiCtrlCreateLabel("", 0, 45, 100, 45)

GUISetState(@SW_SHOW)

WinMove("test", "", 1030,400)

func print($input)

GUICtrlSetData($display, $input);

endfunc

func print1($input)

GUICtrlSetData($display1, $input);

endfunc

;ffffffffffffffffffffffffffffffffffff

Hotkeyset("a","Pause")

Hotkeyset("s","Resume")

Func Pause()

While 1

Sleep(100)

Wend

Endfunc

Func Resume()

Sleep(1)

Endfunc

$count = 0

func test()

while true

print($count)

$count+= 1;

sleep(333);

WEnd

EndFunc

;ffffffffffffffffffffffffffffffffffff

;rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

while 1

sleep(1000);

WEnd

;rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

"`" to start

"a" to pause

's' to resume

the "Resume" doesnot work, the only way to start the counter is to "`" again

Edited by moxinghbian

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

summarize to 2 question:

1 if sleep(1000) is called in the middle of sleep(10000) @ the 5 th second what will happen?

sleep(6000)

or sleep(11000)?

2 sleep() can not prevent interrupt being fired and handled. thus in my Pause() func, I need to disable all the hotkeys except for the key for "Resume()' right?

Edited by moxinghbian

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

you really should take a class..... Welcome to Autoit 1-2-3 ( in my signature below

there is a systematic process to the lay-out of a script

Posted Image

your code... with proper lay-out and... most of all WORKING

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

Global $count = 0
Global $GUI_name = "TEST"
Global $display
Global $display1
Global $paused

HotKeySet("a", "Pause")
HotKeySet("s", "Resume")
HotKeySet("{ESC}", "CLOSE_Clicked");
HotKeySet("`", "test"); start ... and re-start

$main = GUICreate($GUI_name, 104, 103, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$display = GUICtrlCreateLabel("", 0, 0, 100, 45)
$display1 = GUICtrlCreateLabel("", 0, 45, 100, 45)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE_Clicked")

;WinMove($GUI_name, "", 1030, 700); ????
;WinMove("test", "", 1030, 400); ????

While 1
    Sleep(1000);
WEnd

Func print($input)
    GUICtrlSetData($display, $input);
EndFunc   ;==>print

Func print1($input)
    GUICtrlSetData($display1, $input);
EndFunc   ;==>print1

Func Pause()
    $paused = True
    While $paused
        Sleep(100)
        print1("Paused")
    WEnd
    print1("")
EndFunc   ;==>Pause

Func Resume()
    $paused = False
EndFunc   ;==>Resume

Func test()
    $count = 0
    $paused = False
    print1("")
    While True
        print($count)
        $count += 1;
        Sleep(333);
    WEnd
EndFunc   ;==>test

Func CLOSE_Clicked()
    Exit
EndFunc   ;==>CLOSE_Clicked

8)

Edited by Valuater

NEWHeader1.png

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