Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

StopAll


  • Please log in to reply
23 replies to this topic
x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
[example] If i had a had a simple loop

loop {
Send Hello
Sleep 500
}

[as far as i am aware] The only way to stop the loop and have the script not exit, is using Reload. Allthough that has to re-open the script which is visually annoying (icon moves) and if you accidentally hold down a button set as reload it crashes your computer [even if the script has singleinstance force on]

So i wish for

F1::StopAll


MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Why not While?
While ( ctrlVar <> 1 )
{
  ToolTip, Hello
  Sleep, 150
}

F1:: ctrlVar := 1

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
the loop was just an example, i want to stop all timers, loops, running threads & anything else

Ace Coder
  • Members
  • 362 posts
  • Last active: Mar 13 2012 11:44 PM
  • Joined: 26 Oct 2009
F1::Pause
:?: :?:

Or:
LoopLabel:
loop 
{
   Send Hello
   Sleep 500
}
Return

SomeLabel:
Return ;Used by the F1 hotkey via GoTo, meaning it won't Return anywhere, but simply wait around

F1::GoTo,SomeLabel


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
When F1 is pressed with Ace Coder's second example, it does this:
[*:5nmc67vd]Interrupt the loop, starting a new thread.
[*:5nmc67vd]Go to SomeLabel.
[*:5nmc67vd]Return, finishing the F1 hotkey's thread.
[*:5nmc67vd]Resume the loop.Pointless... F1::return has the same effect.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
Just use a variable telling your timers/loops/hotkeys not do do anything. Alternatively, deactivate all running timers and use #if conditions in AHK_L.

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
I would implement this way:
Loop
{
    IfEqual, STOPALL, 1, Break
    Send Hello
    Sleep 500
}
Copy the STOPALL-check at some different positions in the loop (and all other loops), including at the start. For example before any function call starts, which is very time consuming.

No signature.


x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010

Copy the STOPALL-check at some different positions in the loop (and all other loops), including at the start. For example before any function call starts, which is very time consuming.


I would have to put it inbetween every line in my script, because otherwise id i pressed the button mid-thread the thread would still finish. which is not ideal

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
You should put the check at the places where the script interacts with other programs/files. It usually doesn't hurt if it's doing a few calculations or something like that.

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
On an unrelated note, i've found out how Pause works

f4::
#MaxThreads 0 ;meh
#MaxThreads 1
sleep 10000 ;paused for duration
#MaxThreads 10 ;starts whatever it was doing again
return

8)

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
x79animal, plase notice that

Up to two of the following types of threads may be created even when #MaxThreads has been reached: A hotkey, hotstring, OnClipboardChange, or GUI event if the first line of its subroutine is ExitApp, Pause, Edit, Reload, KeyHistory, ListLines, ListVars, or ListHotkeys. Also, the OnExit subroutine will always launch regardless of how many threads exist.


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


  • Guests
  • Last active:
  • Joined: --

Jumps to the specified label and continues execution.

Meaning GoTo should not return to where it was called from, whereas GoSub does return to where it came from. Or is the documentation misleading?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
GoTo and GoSub don't return anywhere. That's what Return does. GoTo jumps to the specified label and continues execution; in Ace Coder's example, continuing execution means executing the next command (Return), which tells it to return from GoSub.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
so again i ask the same question Ace_coder implied
is there somer eason not to use pause?
Never lose.
WIN or LEARN.

adabo
  • Members
  • 385 posts
  • Last active: Jul 30 2015 07:52 PM
  • Joined: 13 May 2010
+1 for the wishlist.