open file in exclusive mode in C#

后端 未结 5 1089
时光说笑
时光说笑 2020-11-30 08:40

I want to open a file for read in exclusive mode, and if the file is already opened by some process/thread else, I want to receive an exception. I tried the following code,

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 09:22

    What you have done is correct.

    If you need what are all files already opened, then there is a way to see by NtQuerySystemInformation

    You may get idea from http://www.codeproject.com/KB/shell/OpenedFileFinder.aspx

    which gets all the files opened in a directory.. which can be extended to a single file whether opened or not...

提交回复
热议问题