Lock file for writing/deleting while allowing any process to read

后端 未结 4 815
再見小時候
再見小時候 2020-12-28 07:58

I am developing an application in C# (.NET), and am having trouble dealing with file locking.

  • My main application (A) needs read/write access to a certain fil
4条回答
  •  不知归路
    2020-12-28 08:40

    though I have not used it, but named Mutex can save your day. Before opening a file in application A, create a mutext like this:

    Mutex(bool initiallyOwned, string name, out bool createdNew)
    

    pass file name as second parameter.

    now when you open a file in application B, again use Mutex if out parameter createdNew is false then file is already opened by A so you can only read it.

提交回复
热议问题