FileSystem.Lock 方法

定义

控制其他进程对使用 Open 函数打开的文件的全部或部分的访问。Controls access by other processes to all or part of a file opened by using the Open function. MyLock 相比,Unlock 功能在文件 I/O 操作方面可为您提供更高的效率和更好的性能。The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. 有关详细信息,请参阅 FileSystemFor more information, see FileSystem.

重载

Lock(Int32)

控制其他进程对使用 Open 函数打开的文件的全部或部分的访问。Controls access by other processes to all or part of a file opened by using the Open function. MyLock 相比,Unlock 功能在文件 I/O 操作方面可为您提供更高的效率和更好的性能。The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. 有关详细信息,请参阅 FileSystemFor more information, see FileSystem.

Lock(Int32, Int64)

控制其他进程对使用 Open 函数打开的文件的全部或部分的访问。Controls access by other processes to all or part of a file opened by using the Open function. MyLock 相比,Unlock 功能在文件 I/O 操作方面可为您提供更高的效率和更好的性能。The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. 有关详细信息,请参阅 FileSystemFor more information, see FileSystem.

Lock(Int32, Int64, Int64)

控制其他进程对使用 Open 函数打开的文件的全部或部分的访问。Controls access by other processes to all or part of a file opened by using the Open function. MyLock 相比,Unlock 功能在文件 I/O 操作方面可为您提供更高的效率和更好的性能。The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. 有关详细信息,请参阅 FileSystemFor more information, see FileSystem.

Lock(Int32)

控制其他进程对使用 Open 函数打开的文件的全部或部分的访问。Controls access by other processes to all or part of a file opened by using the Open function. MyLock 相比,Unlock 功能在文件 I/O 操作方面可为您提供更高的效率和更好的性能。The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. 有关详细信息,请参阅 FileSystemFor more information, see FileSystem.

public:
 static void Lock(int FileNumber);
public static void Lock (int FileNumber);
static member Lock : int -> unit
Public Sub Lock (FileNumber As Integer)

参数

FileNumber
Int32

必需。Required. 任何有效文件数。Any valid file number.

例外

文件模式无效。File mode is invalid.

示例

此示例演示如何使用 LockUnlock 函数。This example illustrates the use of the Lock and Unlock functions. 此示例假定 People.txt 是包含结构的记录的文件 PersonThis 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

注解

LockUnlock 函数在多个进程可能需要访问同一文件的环境中使用。The Lock and Unlock functions are used in environments where several processes might need access to the same file.

LockUnlock 函数始终成对使用。Lock and Unlock functions are always used in pairs. 和的参数 Lock Unlock 必须完全相同。The arguments to Lock and Unlock must be identical.

如果 Record FromRecord 未提供、或且 ToRecord 未提供,则将为整个文件锁定。If Record, or FromRecord and ToRecord are not supplied, the lock will be for the whole file. 如果 Record 单独指定,则将锁定/解锁单个记录。If Record alone is specified the single record will be locked/unlocked.

如果文件已打开以进行顺序输入或输出,则 Lock Unlock 会影响整个文件,而不考虑和指定的范围 FromRecord ToRecordIf 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.

另请参阅

适用于

Lock(Int32, Int64)

控制其他进程对使用 Open 函数打开的文件的全部或部分的访问。Controls access by other processes to all or part of a file opened by using the Open function. MyLock 相比,Unlock 功能在文件 I/O 操作方面可为您提供更高的效率和更好的性能。The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. 有关详细信息,请参阅 FileSystemFor more information, see FileSystem.

public:
 static void Lock(int FileNumber, long Record);
public static void Lock (int FileNumber, long Record);
static member Lock : int * int64 -> unit
Public Sub Lock (FileNumber As Integer, Record As Long)

参数

FileNumber
Int32

必需。Required. 任何有效文件数。Any valid file number.

Record
Int64

可选。Optional. 唯一要锁定或取消锁定的记录号或字节数。Number of the only record or byte to lock or unlock.

例外

文件模式无效。File mode is invalid.

示例

此示例演示如何使用 LockUnlock 函数。This example illustrates the use of the Lock and Unlock functions. 此示例假定 People.txt 是包含结构的记录的文件 PersonThis 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

注解

LockUnlock 函数在多个进程可能需要访问同一文件的环境中使用。The Lock and Unlock functions are used in environments where several processes might need access to the same file.

LockUnlock 函数始终成对使用。Lock and Unlock functions are always used in pairs. 和的参数 Lock Unlock 必须完全相同。The arguments to Lock and Unlock must be identical.

如果 Record FromRecord 未提供、或且 ToRecord 未提供,则将为整个文件锁定。If Record, or FromRecord and ToRecord are not supplied, the lock will be for the whole file. 如果 Record 单独指定,则将锁定/解锁单个记录。If Record alone is specified the single record will be locked/unlocked.

如果文件已打开以进行顺序输入或输出,则 Lock Unlock 会影响整个文件,而不考虑和指定的范围 FromRecord ToRecordIf 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.

另请参阅

适用于

Lock(Int32, Int64, Int64)

控制其他进程对使用 Open 函数打开的文件的全部或部分的访问。Controls access by other processes to all or part of a file opened by using the Open function. MyLock 相比,Unlock 功能在文件 I/O 操作方面可为您提供更高的效率和更好的性能。The My feature gives you better productivity and performance in file I/O operations than Lock and Unlock. 有关详细信息,请参阅 FileSystemFor more information, see FileSystem.

public:
 static void Lock(int FileNumber, long FromRecord, long ToRecord);
public static void Lock (int FileNumber, long FromRecord, long ToRecord);
static member Lock : int * int64 * int64 -> unit
Public Sub Lock (FileNumber As Integer, FromRecord As Long, ToRecord As Long)

参数

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.

例外

文件模式无效。File mode is invalid.

示例

此示例演示如何使用 LockUnlock 函数。This example illustrates the use of the Lock and Unlock functions. 此示例假定 People.txt 是包含结构的记录的文件 PersonThis 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

注解

LockUnlock 函数在多个进程可能需要访问同一文件的环境中使用。The Lock and Unlock functions are used in environments where several processes might need access to the same file.

LockUnlock 函数始终成对使用。Lock and Unlock functions are always used in pairs. 和的参数 Lock Unlock 必须完全相同。The arguments to Lock and Unlock must be identical.

如果 Record FromRecord 未提供、或且 ToRecord 未提供,则将为整个文件锁定。If Record, or FromRecord and ToRecord are not supplied, the lock will be for the whole file. 如果 Record 单独指定,则将锁定/解锁单个记录。If Record alone is specified the single record will be locked/unlocked.

如果文件已打开以进行顺序输入或输出,则 Lock Unlock 会影响整个文件,而不考虑和指定的范围 FromRecord ToRecordIf 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.

另请参阅

适用于