open file in exclusive mode in C#

后端 未结 5 1091
时光说笑
时光说笑 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条回答
  •  难免孤独
    2020-11-30 09:17

    FileShare.None will only work if another process has also opened the file without allowing it to be shared for reads.

    Programs such as Notepad and Visual Studio do not lock text files.

提交回复
热议问题