[ Trick] single instance runnable
Posted: Mon Feb 24, 2020 1:21 pm
Hello all,
if you want of users cannot be run more one instance of your executable, see this code below (only for windows)
if you want of users cannot be run more one instance of your executable, see this code below (only for windows)
Code: Select all
#MyApp="Your message"
Mutex=CreateMutex_(0,1,#MyApp)
If GetLastError_()=#ERROR_ALREADY_EXISTS
MessageRequester(#MyApp,"one instance is already running",#PB_MessageRequester_Error)
End
EndIf
; your main code
#MAIN_FORM = 0
OpenWindow(#MAIN_FORM,0,0,800,600,"Hello world",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Repeat
WaitWindowEvent()
Until Event() = #PB_Event_CloseWindow
; don't forget to unlock the mutex
ReleaseMutex_(Mutex)
End