我有一个 192k 大小的文件,我想锁定文件的中间部分。
Ex) 我想用 C# 锁定文件的 64k-128k。知道如何锁定文件的那部分吗?
最佳答案
您需要使用 LockFileEx
Locks the specified file for exclusive access by the calling process. This function can operate either synchronously or asynchronously and can request either an exclusive or a shared lock.
您正在寻找共享锁。
[DllImport("kernel32.dll")]
static extern bool LockFileEx(IntPtr hFile, uint dwFlags, uint dwReserved,
uint nNumberOfBytesToLockLow, uint nNumberOfBytesToLockHigh,
[In] ref System.Threading.NativeOverlapped lpOverlapped);
关于c# - 锁定文件 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12478271/