AutoHotkey Community

It is currently May 27th, 2012, 2:02 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Script not Exiting
PostPosted: January 30th, 2010, 2:12 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
I need help in understanding why the script doesn't Exit at the "Exit" command .. but only once Returned from here:
How should i deal with this :?:

Help..Exit wrote:
Exits the current thread or (if the script is not persistent contains no hotkeys) the entire script


Code:
SetTimer, here, -1000

MsgBox,,,,3

Exit

here:
  sleep 5000
  msgbox,,,reached here!,2
return


Last edited by a_h_k on February 1st, 2010, 8:07 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Script not Exiting
PostPosted: January 30th, 2010, 4:03 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
a_h_k wrote:
Code:
SetTimer, here, -1000
MsgBox,,,test,3
Exit

here:
  sleep 5000
  msgbox,,,reached here!,2
return


1) Timer is set
2) MsgBox (test) appears
3) when MsgBox (test) has been displayed for 1 second, the trigger for label "here" is fired
4) at this point, MsgBox (test) is still there while Sleep command is being performed
5) "test" MsgBox's timeout is interpreted as still being part of the MsgBox Command, so it will disappear but will not perform the Exit command since the commands from label "here" are being performed
6) after the Sleep command, MsgBox (reached) appears and then times out
7) finnaly, label "here" Returns, allowing the script to continue from where it stopped [right after the first MsgBox] and the Exit command is reached

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2010, 5:17 am 
Offline

Joined: November 23rd, 2009, 2:11 pm
Posts: 104
http://www.autohotkey.com/docs/commands/ExitApp.htm
try this :wink:

_________________
  /\ /\ This is Kitty
(>';'<) Cut, copy, and paste kitty onto your sig.
((")(")) Help Kitty gain World Domination.

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2010, 5:18 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
I suppose he just wants to understand why that doesn't work.

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Script not Exiting
PostPosted: January 30th, 2010, 5:27 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
The same happens with sleep

Scenario #1 - 1st Sleep finishes after 2nd Sleep
Code:
SetTimer, here, -1000

Sleep, 11000   ;MsgBox,,,,11
msgbox,,,next,1

Exit

here:
  sleep 5000
  msgbox,,,reached here!,2
return

1) Timer is set
2) Sleeps for 1 second
3) Calls routine "here" (& "Sleep 11000" carries on with it's sleeping)
4) "Sleep 5000" begins it's sleep
5) "Sleep 5000" finishes ("Sleep 11000" down to 5000 left)
6) Msgbox "reached here!" is displayed (for 2 secs)
7) Label "here" Returns to main script (which is still running "Sleep 11000" --> now down to 3000 left)
8) "Sleep 11000" finishes
9) Msgbox "next" displayed (for 1 sec)

So it can be seen that the label "here" and main script are being executed simulataneously (ie multi-threading)

Scenario #2 - 1st Sleep finishes before 2nd Sleep
Code:
SetTimer, here, -1000

Sleep, 3000   ;MsgBox,,,,3
msgbox,,,next,1

Exit

here:
  sleep 5000
  msgbox,,,reached here!,2
return

1) Timer is set
2) Sleeps for 1 second
3) Calls routine "here" (& "Sleep 3000" carries on with it's sleeping - 2000 left)
4) "Sleep 5000" begins it's sleep (within which "Sleep 3000" times-out)
This where (during above sleep) i think the main should execute the next commnad (the msgbox "next")
As i stated above, the thread "here" & main script = being executed independently, with main running the command after SetTimer (Sleep 3000), so why not also the 2nd command after??
5) "Sleep 5000" finishes ("Sleep 3000" expired)
6) Msgbox "reached here!" is displayed (for 2 secs)
7) Label "here" Returns to main script
8) Msgbox "next" displayed (for 1 sec)


Last edited by a_h_k on February 1st, 2010, 7:45 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 30th, 2010, 5:34 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Yeah. I'm not sure how Sleep and MsgBox are coded (never checked AHK's source code). But I must say original AHK itself can't multithread AFAIK. I'm not an AHK Guru so I can't explain these things for sure.

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2010, 8:08 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Did a basic test, using a non-modal MsgBox .. worked (as predicted)

Code:
SetTimer, here, -1000

MsgBoxNonModal("test")          ;,,,,3 (haven't incorporated timeout yet)
msgbox reached here first!!     ;ie using non-modal msgbox allows code following MsgBox.. line to execute BEFORE returned from here

Exit

here:
  sleep 5000
  msgbox, reached here!
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2010, 8:11 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
For interest, my other "parallel" thread --> Make MsgBox AlwaysOnTop + Inactive


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, engunneer, Google Feedfetcher, JSLover, rbrtryn, sjc1000 and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group