Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A New Twist On Is App Running
Message
From
25/08/2000 09:45:37
 
 
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00409058
Message ID:
00409184
Views:
34
Ed,

Thanks!

I don't normally send messages that just say thank you but in this case it's warranted.

Best,

DD

>>I have an application that runs in the background. There is no user intervention via the application. One issue I have is people running the application more than one cause they cannot see it is running. I need to be able to detect the running app without using the Title bar as part of the solution. So I can just ignore someone trying to run it again.
>>
>>
>>Any Ideas? George :)
>>
>
>I'm not George, but I like using the native Event object for the OS via a couple of API calls:
>
>
DECLARE INTEGER CreateEvent IN WIN32API ;
>   INTEGER lpEventAttributes, ;
>   SHORT bManualReset, ;
>   SHORT bInitialState, ;
>   STRING @ lpName
>DECLARE INTEGER GetLastError IN Win32API
>DECLARE CloseHandle IN Win32API INTEGER hObject
>nEh = CreateEvent(0,0,1, PROGRAM(0) + '.EVENT')
>IF GetLastError() = 183 OR nEh = 0
>   *  There's an instance running already (183) or the Event can't be defined
>   *  So don't do it;  do release the handle, since it's harmless and should
>   *  be done rather than relying on Windows to clean up after itself
>   =CloseHandle(nEh)
>   QUIT
>ENDIF
>
>*  While shutting down, issue:
>=CloseHandle(nEh)
>
>This has the advantage that it derives it's Event name from the executable, and if you do forget to issue a CloseHandle(), it still releases the Event object without bleeding, and the Event object completely disappears automagically when no remaining Event refs exist. CLOSE ALL will release the Event. You can use the Event for synchronizing several processes or thread using WaitForSingleObject() to wait on someone to 'raise' the event if you need some sort of event monitoring. Works under all OS versions I tested - not checked under Win95, but does work on Win98 and ME, as well as NT and 2K.
>
>You can use any name you want if linking to the app's initial program doesn't work for you - I chose that because it's easy to get right, and presumably you want to block other instances of the app you're starting.
Best,


DD

A man is no fool who gives up that which he cannot keep for that which he cannot lose.
Everything I don't understand must be easy!
The difficulty of any task is measured by the capacity of the agent performing the work.
Previous
Reply
Map
View

Click here to load this message in the networking platform