Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A New Twist On Is App Running
Message
De
31/05/2007 04:23:06
 
 
À
31/05/2007 04:12:39
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00409058
Message ID:
01229509
Vues:
18
Hi John.

Thanks for the reply. If I use:
nEH = CreateEvent(0,0,1, CHRTRAN(_VFP.ServerName + '.EVENT',"\","_"))
I get a non-zero handle number and geterror() = 0. When I load the second instance of the app I get the same handle number and geterror() still returns 0. Hence both apps load.

In respect of a code sample, I am using the exact code as per Ed's original post below. No change. If I use PROGRAM(0) same thing. For both instances that I load of the exe I get the same PROGRAM(0) (my start program), I get the same handle for both, and no error. Therefore the line:
IF GetLastError() = 183 OR lnEH = 0
does not result in .T. There is no error and I get a non-zero handle.

Just a reminder, I'm running Windows Vista Business for this test.



>Hi Jos,
>
>On the _VFP.ServerName you need to fix the code like this for it to work:
>
>
>nEH = CreateEvent(0,0,1, CHRTRAN(_VFP.ServerName + '.EVENT',"\","_"))
>
>
>See http://msdn2.microsoft.com/en-us/library/ms682396.aspx for info about the \ character in event names.
>
>On the PROGRAM(0) not working I have one or two ideas but without code to look at they are just guesses. But I would guess that either PROGRAM(0) is returning something different for each instance, or it is returning Local\something or you are some how releasing the handle before the the application quits.
>
>I would check that CloseHandle(nEH) and CLEAR ALL are definitely not being called. And see what PROGRAM(0) is returning.
>
>You can also hard code an event name like:
>
>
>nEH = CreateEvent(0,0,1,'JosPolsIsTestingThis.Event')
>
>
>Here is runnable code for testing:
>
>
>***********************************************************************
>*TestEvent.prg  if you name it something else change the DO TestEvent
>*line to what you named this.
>***** No Dual Instances Code ******************************************
>
>LOCAL lnEH
>
>IF TYPE("nDepth") = "U"
>  nDepth = 0
>  CLEAR
>  ? "First Call creates an event named: "+PROGRAM(0) + '.EVENT'
>ELSE
>  ? "Starting the Recursive Call: "+PROGRAM(0) + '.EVENT'
>ENDIF
>IF nDepth>1
>  ? "Error I was allowed to Execute"
>  RETURN
>ENDIF
>
>lnEH = CreateEvent(0,1,1, PROGRAM(0) + '.EVENT')
>
>IF GetLastError() = 183 OR lnEH = 0
>   ? "Quiting because we are Already Running",lnEH
>   *  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(lnEH)
>   RETURN
>ENDIF
>
>nDepth = nDepth + 1
>? "Doing Recursive Call",lnEH
>DO TestEvent
>
>*  While shutting down, issue:
>=CloseHandle(lnEH)
>RETURN
>
>
>John
>
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform