AutoHotkey Community

It is currently May 27th, 2012, 11:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: November 17th, 2010, 12:16 pm 
Offline

Joined: July 15th, 2005, 3:19 pm
Posts: 140
Location: Denmark
I placed this thread in the bug report thread as it has so severe consequenses.

The following code will force you to *RESTART* your computer, so be sure to save everything before trying. The script requires
http://www.autohotkey.com/forum/viewtopic.php?t=43049&highlight=dll:
Code:
SetBatchLines -1
AhkDll:=A_ScriptDir "\AutoHotkey.dll"
hModule:=DllCall("LoadLibrary","Str",AhkDll)
threadedScript =
   ( % Comments
   Loop
   {
      varA--
      tooltip, %varA%, 100, 1, 3
   }
   )

DllCall(AhkDll "\ahktextdll","Str",threadedScript,"Str","","Str","","Cdecl Uint")

Loop {
 varB++
 tooltip, %varB%, 200, 1
 reload
}


The way I came across this bug, was the worst possible way... I had included a reload, which should restart a script in a production environment once a day. The reason for this restart was a memory leak in a custom built DLL. I can just say that quite a bit of time and data was lost because if this issue.

I believe the solution would be to create a reload function, which can handle that there are multiple threads.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2010, 1:29 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
This is not related to AutoHotkey.dll.
e.g. try this:
Code:
MsgBox
Loop {
 ToolTip % A_Index
 reload
}


The problem seems to be due Reload command from AutoHotkey being executed in the loop, so it starts the script but does not wait until the other finishes closing.
To fix that simply do not put Reload command into the loop. or include a Sleep, 100 after Reload.
Code:
MsgBox
Loop {
 ToolTip % A_Index
 reload
 Sleep 100
}


AutoHotkey Help - Reload wrote:
If the script cannot be reloaded -- perhaps because it has a syntax error -- the original instance of the script will continue running. Therefore, the reload command should be followed by whatever actions you want taken in the event of a failure (such as a return to exit the current subroutine)

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2010, 1:58 pm 
Offline

Joined: July 15th, 2005, 3:19 pm
Posts: 140
Location: Denmark
Imagine the following functionality. Reload will check whether a pid can be obtained for the new process. If a new PID is obtained, exitapp is called, if not then the script continues running. Wouldn't that be a lot more intuitive?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2010, 2:13 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
This is what you can do manually and it is shown in AutoHotkey help file
Code:
Reload
Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
IfMsgBox, Yes, Edit
return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 18th, 2010, 6:17 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
David Andersen wrote:
If a new PID is obtained, exitapp is called, if not then the script continues running.
That would not be sufficient. Consider the example given in the help file (quoted by HotKeyIt):
Quote:
If the script cannot be reloaded -- perhaps because it has a syntax error
AutoHotkey.exe starts, a PID is obtained but it encounters an error while loading the script. It will generally continue to run until the user closes the error dialog. Meanwhile the original script continues to run.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2010, 12:04 pm 
Offline

Joined: July 15th, 2005, 3:19 pm
Posts: 140
Location: Denmark
In at least one case
Code:
Reload
Sleep 1000


will be unreliable. For example it is used in a compiled script, which is placed on a networked drive and accessed over VNC. In this case the whole .exe file needs to be transferred over the internet and this might be a lot slower than the one second delay. I however, do not see any simple solutions to this case, and it is a very special case.

The documentation on the reload function is very good, so I will find a solution suitable in my case.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 27 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