Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Viewing locked file
Message
De
10/01/2021 09:03:44
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01677774
Message ID:
01677785
Vues:
58
lod = CREATEOBJECT("session")
SET DATASESSION lod.datasessionid
CREATE CURSOR t_sema(rec I, tx ch(50))
INSERT INTO t_sema (rec, tx) values(1, "hallo")
SET DATASESSION TO 1
CLOSE TABLES all
CLOSE DATABASES all
SET DATASESSION lod.datasessionid
BROWSE
Have NOT checked or tried to implement something similar via vfp stored proc, but when trying for something thought to be impossible by others they helped me sometimes - but you have to be creative...

if your code has provisions to centralize closing etc, such sessions need to be handled different of course.
But in view of ease and other benefits IMO your argument fails...


>See my reply to Al Doman for why I prefer not to use vfp tables for semaphores.
>>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