>>>>>>I want also to be sure that if the user shuts down his/her computer, the lock on the file 'MyFile' is released.
>>>>>>
>>>>>>TIA
>>>>>
>>>>>It looks OK to me and it is also easy to test, you can test it with 2 instances of VFP, you don't really need 2 computers.
>>>>
>>>>A test in 2 VFP IDE does not seem to work. I opened two instances of VFP IDE. I lock the file in one VFP. Then try to lock in another, returns -1. But when I go back to the 1st one and fclose( nHadle), the second instance of VFP IDE still cannot lock the file (returns -1).
>>>>What am I missing?
>>>>
>>>>UPDATE. Now I opened two instances of VFP IDE and can lock the same file in both (using fopen('filename',0)). I am not sure that testing on one computer is possible.
>>>
>>>I did that same test right now (Windows 10) and it worked correctly to me (although I used 12 as attribute, because 12 is the one to lock the file).
>>
>>One other observation. If I lock the file (with attribute 12) in one instance of VFP and then close the VFP without using FCLOSE(), I cannot lock it in another instance of VFP. Unless there is some kind of time-out until OS will release the lock on the file.
>
>So, this is the answer on the second part of your question. Most likely if your application will not be shutdown properly, the file will remain locked. I do remember long time ago we did unlock files using some special tool.
Therefore I cannot use this semaphore locking approach. Because sooner or later it will fail and there will be a problem. So I will work on another approach.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham