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.
IF GetLastError() = 183 OR lnEH = 0does not result in .T. There is no error and I get a non-zero handle.
>nEH = CreateEvent(0,0,1, CHRTRAN(_VFP.ServerName + '.EVENT',"\","_")) >>
>nEH = CreateEvent(0,0,1,'JosPolsIsTestingThis.Event') >>
>*********************************************************************** >*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 >>