Jump to content

.a3x Demo


Skysnake
 Share

Recommended Posts

In the help file for _Singleton it says:

#include <Misc.au3>
_Singleton ( $sOccurrenceName [, $iFlag = 0] )

Parameters

$sOccurrenceName String to identify the occurrence of the script. This string may not contain the \ character unless you are placing the object in a namespace (See Remarks).

 

My problem is that I have no idea where to find the string that identifies the occurrence of the script. I tried the name of the script as this seemed most logical.

If _Singleton("QuickAccess.a3x",1) = 0 Then
        MsgBox(0,"QuickAccess.a3x","This is already running")
        Exit
    Else
        MsgBox(0,"QuickAccess.a3x","This was not found")
    EndIf

This seemed to work, but then I tried a different script name which wasn't running and got the same result. It said the non existant script was running... So I decided that I hadn't understood the use of the _singleton function which I think would be more helpful than the WinExists as described by Argumentum above. In the help file it uses the string "test". This is obviously not the full script name so I tried the name before the extension and got the same unhelpful results.

Then I tried a different test and it told me that none of the scripts were found even though two were running.

Blessings

Link to comment
Share on other sites

I did another test and that gave even more strange results.

Func TestSingleton()

    $a = "Launch"
    $b = "QuickAccess"
    $c = "RunTempMMexe"
    Dim $Files[3] = [$a, $b, $c]
    
For $I = 0 To 2
    If _Singleton("QuickAccess",1) = 0 Then
        MsgBox(0,$Files[$I],"This is already running")
        Exit
    Else
        MsgBox(0,$Files[$I],"This was not found")
    EndIf
Next
EndFunc

It only went through the loop twice and for the SAME text gave two different results.

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "U:\Documents\.......\Test.au3" /UserParams    
+>14:00:18 Starting AutoIt3Wrapper v.15.920.938.0 SciTE v.3.6.0.0   Keyboard:00000809  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0809)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:U:\Documents\....\Test.au3
+>14:00:18 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "U:\Documents\......\Test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>14:00:36 AutoIt3.exe ended.rc:0
+>14:00:36 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 19.38

I look forward to any explanation you have.

Blessings

 

Link to comment
Share on other sites

  • Developers

Ok... so i ended up typing the few lines myself to be able to test. This works fine for me:

#include <misc.au3>
$Scriptname = @ScriptName
If _Singleton($Scriptname, 1) = 0 Then
    ConsoleWrite($Scriptname & " is already running" & @CRLF)
    Exit
Else
    ConsoleWrite($Scriptname & " is Not running" & @CRLF)
EndIf
Sleep(10000)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

OK. I think that my problem was that I misunderstood the aim of _singleton. It allows a script to detect if the script itself is already running, the value of the string you use is irrelevant - any string will do.

I was hoping to be able in one script to detect if another script was running and for that I need to use WinExists.

Blessings

Link to comment
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
 Share

×
×
  • Create New...