Sign in to follow this  
Followers 0
IvanCodin

Run one script

8 posts in this topic

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Varian

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Varian

Share this post


Link to post
Share on other sites

Thanks! That make it perfectly clear for me. One line of code does it all!! :-)

Me

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