What's the least invasive way to read a locked file in C# (perhaps in unsafe mode)?

前端 未结 3 606
猫巷女王i
猫巷女王i 2020-11-29 09:22

I need to read a Windows file that may be locked, but I don\'t want to create any kind lock that will prevent other processes from writing to the file.

In addition,

3条回答
  •  孤街浪徒
    2020-11-29 09:26

    You can probably create a copy and read that, even if the file is locked.

    Or maybe a StreamReader on a FileStream depending on how SQL opened the file?

    new FileStream("c:\myfile.ext", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    

提交回复
热议问题