FileSystem.Lock Method

Definition

Controls access by other processes to all or part of a file opened by using the Open function. The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. For more information, see FileSystem.

Overloads

Lock(Int32)

Controls access by other processes to all or part of a file opened by using the Open function. The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. For more information, see FileSystem.

Lock(Int32, Int64)

Controls access by other processes to all or part of a file opened by using the Open function. The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. For more information, see FileSystem.

Lock(Int32, Int64, Int64)

Controls access by other processes to all or part of a file opened by using the Open function. The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. For more information, see FileSystem.

Lock(Int32)

Controls access by other processes to all or part of a file opened by using the Open function. The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. For more information, see FileSystem.

public static void Lock (int FileNumber);
Parameters
FileNumber
Int32

Required. Any valid file number.

Exceptions

File mode is invalid.

Examples

This example illustrates the use of the Lock and Unlock functions. This example assumes that People.txt is a file that contains records of the structure Person.

Structure Person
    Dim Name As String
    Dim ID As Integer
End Structure

Sub PutInLockedFile(ByVal onePerson As Person)
    FileOpen(1, "c:\people.txt", OpenMode.Binary)
    Lock(1)
    FilePut(1, onePerson)
    Unlock(1)
    FileClose(1)
End Sub

Remarks

The Lock and Unlock functions are used in environments where several processes might need access to the same file.

Lock and Unlock functions are always used in pairs. The arguments to Lock and Unlock must be identical.

If Record, or FromRecord and ToRecord are not supplied, the lock will be for the whole file. If Record alone is specified the single record will be locked/unlocked.

If the file has been opened for sequential input or output, Lock and Unlock affect the whole file, regardless of the range specified by FromRecord andToRecord.

See Also

Lock(Int32, Int64)

Controls access by other processes to all or part of a file opened by using the Open function. The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. For more information, see FileSystem.

public static void Lock (int FileNumber, long Record);
Parameters
FileNumber
Int32

Required. Any valid file number.

Record
Int64

Optional. Number of the only record or byte to lock or unlock

Exceptions

File mode is invalid.

Examples

This example illustrates the use of the Lock and Unlock functions. This example assumes that People.txt is a file that contains records of the structure Person.

Structure Person
    Dim Name As String
    Dim ID As Integer
End Structure

Sub PutInLockedFile(ByVal onePerson As Person)
    FileOpen(1, "c:\people.txt", OpenMode.Binary)
    Lock(1)
    FilePut(1, onePerson)
    Unlock(1)
    FileClose(1)
End Sub

Remarks

The Lock and Unlock functions are used in environments where several processes might need access to the same file.

Lock and Unlock functions are always used in pairs. The arguments to Lock and Unlock must be identical.

If Record, or FromRecord and ToRecord are not supplied, the lock will be for the whole file. If Record alone is specified the single record will be locked/unlocked.

If the file has been opened for sequential input or output, Lock and Unlock affect the whole file, regardless of the range specified by FromRecord andToRecord.

See Also

Lock(Int32, Int64, Int64)

Controls access by other processes to all or part of a file opened by using the Open function. The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. For more information, see FileSystem.

public static void Lock (int FileNumber, long FromRecord, long ToRecord);
Parameters
FileNumber
Int32

Required. Any valid file number.

FromRecord
Int64

Optional. Number of the first record or byte to lock or unlock.

ToRecord
Int64

Optional. Number of the last record or byte to lock or unlock.

Exceptions

File mode is invalid.

Examples

This example illustrates the use of the Lock and Unlock functions. This example assumes that People.txt is a file that contains records of the structure Person.

Structure Person
    Dim Name As String
    Dim ID As Integer
End Structure

Sub PutInLockedFile(ByVal onePerson As Person)
    FileOpen(1, "c:\people.txt", OpenMode.Binary)
    Lock(1)
    FilePut(1, onePerson)
    Unlock(1)
    FileClose(1)
End Sub

Remarks

The Lock and Unlock functions are used in environments where several processes might need access to the same file.

Lock and Unlock functions are always used in pairs. The arguments to Lock and Unlock must be identical.

If Record, or FromRecord and ToRecord are not supplied, the lock will be for the whole file. If Record alone is specified the single record will be locked/unlocked.

If the file has been opened for sequential input or output, Lock and Unlock affect the whole file, regardless of the range specified by FromRecord andToRecord.

See Also

Applies to