Solved

for 500pts <> File Locking and Unlocking. How its work?

Posted on 2006-10-21
1
139 Views
Last Modified: 2010-04-30
Hello Experts,
I have a structured file with only 2 records
File name : Gate.dts
Record Length: 3bytes
Structure :
Type Gate
    FileNo As Byte           '1
    atUse As Boolean       '2
End Type


this file open by process 1 (P#2)

Close #400: Open strCachePath & "Gate.dts" For Random Shared As #400 Len = 3

read some data
Get #400, 1, Gate

write some data
    Lock #400, 2
    Gate.atUse = True
    Put #400, 2, Gate
    Unlock #400, 2

This two records are regulary update by a second Process (P#2) say every 30 seconds
Similary P#1 need to  read and write data to Gate.dts
P#1 reading these records every 30 seconds or so

I'd like to give priority to P#2 if I can

now
1) when I reding data do I need to Lock and Unlock?
2) what will hapen if P#2 is writing to Gate.dts record 1 and P#1 want to read it same time? will it crash?

________________________________________
Aditional Information

in this scenario P#1 and P#2 are in different computers connected though network. P#1 act like a server.
some occations there could be more than one clients and can have multiple of P#2 process and Gate.dts.
Gate.dts located in client machines only

0
Comment
Question by:udanabanana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17783342
1) No. Locking is only relevant to writing.
2) No. You can read a locked record.
If you try to write to a locked record, you will can an error, not a crash.
The error is 70, Permission denied.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question