IvanCodin Posted February 16, 2011 Share Posted February 16, 2011 When I use the code below it should see if Tools is running? If _Singleton("Tools", 1) = 0 Then ; script is already running MsgBox(0, "tools", "Tools is already running. Multiple copies cannot be run at once!") Exit EndIf The Help File says it indentifies the occurance of the script. How is that done? Is it when I create a GUI like this: $hGUI1=GUICreate("Tools" 450, 440, 270, 95) or do I have to set the window name to Tools somehow? So how do I set the occurance name? Me Link to comment Share on other sites More sharing options...
Varian Posted February 16, 2011 Share Posted February 16, 2011 Add this to your GUI script:#include <Misc.au3> _Singleton("Tools", 1) Link to comment Share on other sites More sharing options...
Rogue5099 Posted February 16, 2011 Share Posted February 16, 2011 If I'm not mistaken _Singleton only checks to make sure that you don't run the same Script twice. i.e. Run Test.exe, then run Test.exe again and you should get the error of it already existing. My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Varian Posted February 16, 2011 Share Posted February 16, 2011 (edited) If I'm not mistaken _Singleton only checks to make sure that you don't run the same Script twice. i.e. Run Test.exe, then run Test.exe again and you should get the error of it already existing. No, you can add _Singleton("SomeName", 1) to any script, compiled or not compiled and it would register as the same name in Singelton. If you added _Singleton("SomeName") to the top of various scripts, only the first one would run...the others would exit since they all have the same name in the Singelton call Edited February 16, 2011 by Varian Link to comment Share on other sites More sharing options...
IvanCodin Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks for the reply!! I thought I understood what the singleton does, I may be wrong :-). I may be misunderstaning but thought singleton looks for a script running with the name specified in singleton. So _Singleton("SomeName", 1) only lets one instance of SomeName run. Where is that name set? Is it the GUI Title Name? Me Link to comment Share on other sites More sharing options...
Varian Posted February 17, 2011 Share Posted February 17, 2011 (edited) Thanks for the reply!! I thought I understood what the singleton does, I may be wrong :-). I may be misunderstaning but thought singleton looks for a script running with the name specified in singleton. So _Singleton("SomeName", 1) only lets one instance of SomeName run. Where is that name set? Is it the GUI Title Name? Me I may have messed you up, but you were on the right track with your previous thoughts. Singleton is the tag. If your GUI script had _Singleton("Tools") and is running and your other script had If _Singleton("Tools",1) = 0 Then MsgBox(0, "Error", "Another instance is runnging") Exit Else MsgBox(0, "OK", "No other instances are running") EndIf then the second script would give the error MsgBox and then exit. Think of it as another way of identifying the script...rather than by Window Title, by PID, or by Process Name. _Singleton("SomeName") creates a tag identifying it as "SomeName". Singleton creates and looks for the specified tag name simultaneously. Singleton does not look for Window Titles or process names or PIDs...only for the Singleton tag Edited February 17, 2011 by Varian Link to comment Share on other sites More sharing options...
Rogue5099 Posted February 17, 2011 Share Posted February 17, 2011 @Varian Thanks for clarifing. I was mistaken. My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
IvanCodin Posted February 18, 2011 Author Share Posted February 18, 2011 Thanks! That make it perfectly clear for me. One line of code does it all!! :-) Me Link to comment Share on other sites More sharing options...
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