>Hi,
>
>I am working on creating a semaphore file (e.g. "semaphore001.log"). The file can be created by the VFP 9 application by
>
>nHandle = FCREATE("semaphore001.log")
>if nHandle > 0
> ** success
>endif
>
>But in the above method, the file "semaphore001.log" has no information about the user.
>
>I can also create the file by:
>
>strtofile( "User: John Smith", "semaphore001.log" )
>nHandle = fopen( "semaphore001.log", 2 )
>if nHandle > 0
> ** success
>endif
>
>
>But in the second approach, I cannot view the content of the file either from the command prompt or from the application.
>
>Is there a way to view the content of a locked file from either command prompt or from the application?
What do you get if you modify the second approach:
strtofile( "User: John Smith", "semaphore001.log" )
nHandle = fopen( "semaphore001.log", 2 )
if nHandle > 0
nHandle2 = fopen( "semaphore001.log" )
?nHandle2
endif
What are you trying to do? There might be other ways to do what you want.
Another approach to semaphores (with VFP) is to use a VFP free table. One way is to have a single row in the table, which might include information column(s) such as Name. A user can open the table SHARED, then try to FLOCK() it. If they succeed, they update the name column so everyone who opens the table knows who has the lock. When finished they UNLOCK the table. They can optionally blank the name column before UNLOCKing, or leave it so everyone knows who last had a lock.
A variation on that is to have a free table with one row per user, who can RLOCK() their own record. This may not be suitable for your use case.
I seem to recall other users (not me) using API functions and Windows mutexes, you might find something by searching here for "mutex".
Regards. Al
"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov
Neither a despot, nor a doormat, be
Every app wants to be a database app when it grows up