Functions
ID #1051
How to deny recurring run of application?
Most reliable method is using of named kernel object - event or mutex. Even if application hangs with GPF kernel will free such resource automatically.
Example
MAP MODULE('user32') api_CreateMutex(UNSIGNED _lpMutexAttr,SIGNED _bInitialOwner,*CSTRING _lpName), | SIGNED,RAW,PASCAL,NAME('CreateMutexA') api_ReleaseMutex(UNSIGNED _hMutex),SIGNED,PASCAL,PROC,NAME('ReleaseMutex') api_CloseHandle(UNSIGNED _hObject),SIGNED,PASCAL,PROC,NAME('CloseHandle') END END ! Global data GLO:lpMutexName CSTRING('This_Is_My_Mutex') GLO:loAppMutex LONG CODE GLO:loAppMutex = api_CreateMutex(0,TRUE,Glo:lpMutexName) IF api_GetLastError() = 183 MESSAGE('Application is alredy running','Attention',ICON:Asterisk) RETURN END Main ! Main procedure IF GLO:loAppMutex api_ReleaseMutex(GLO:loAppMutex) api_CloseHandle(GLO:loAppMutex) END
Tags: application, mutex, recurring run
Related entries:
- How to prevent running of Application Wizard creating new application?
- How to change first calling procedure when application started?
- How to know if user leave the application?
- How to run application that will not be displayed in task bar?
- How to read from application environment variable?
Last update: 2007-07-17 10:03
Author: Aleksey Timkov
Revision: 1.0
You can comment on this entry