gpt4 book ai didi

c# - 锁定文件 block

转载 作者:行者123 更新时间:2023-11-30 19:18:30 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com