Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Viewing locked file
Message
De
10/01/2021 08:38:47
 
 
À
10/01/2021 02:07:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01677774
Message ID:
01677782
Vues:
47
Al already said it all - use a semaphore table with row locks unless reaction times come close to real time.
You use vfp - so use its strength...

>>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
>  ** success
>
>  * Now simulate something else trying to open the file:
>  nHandle2 = fopen( "semaphore001.log" )
>  ?nHandle2
>  * If nHandle2 = 0 then failure, nHandle is exclusive and other processes can't open the file
>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".
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform