Code: Select all
Procedure RunOnce()
Protected Res=#False, r, ProgID.s
ProgID=UCase(StringFingerprint(GetCurrentDirectory(), #PB_Cipher_SHA1))
r = CreateSemaphore_(#Null, 0, 1, "Semaphore"+ProgID)
If r<>0
If GetLastError_()=#ERROR_ALREADY_EXISTS ; Копия приложения уже запущена.
CloseHandle_(r)
Res=#True
EndIf
EndIf
ProcedureReturn Res
EndProcedure
UseSHA1Fingerprint()
Debug RunOnce()
Debug RunOnce()But if you turn it on "Create threadsafe executable" then this result will be in the debug window0
1
This means that when multithreading is enabled, the code does not work correctly.0
0
