锁定文件块 [英] Lock a block of a file

查看:49
本文介绍了锁定文件块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大小为192k的文件,我想锁定文件的中间位置.

I have a file that is 192k in size, I want to lock the middle of the file.

例如)我想用c#锁定文件的64k-128k.知道我将如何锁定文件的那一部分吗?

Ex) I would like to lock 64k-128k of the file with c#. Any idea how I would lock that part of the file?

推荐答案

您将需要使用

锁定指定的文件,以供调用进程进行独占访问.此功能可以同步或异步操作,并且可以请求排他锁或共享锁.

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);

这篇关于锁定文件块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆