Should I dispose a Mutex?

前端 未结 3 679
天命终不由人
天命终不由人 2020-12-10 12:24

I\'m working on 2 Windows Services that have a common database which I want to lock (cross-process) with a system Mutex.

Now I\'m wondering whether it\'s ok to just

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 12:49

    You need to dispose the resources which are used by the waithandle.

    From the documentation:

    Releases all resources used by the current instance of the WaitHandle class. (Inherited from WaitHandle.)

    The waithandle uses unmanaged resources which should be disposed at the end of use.

    MSDN Documentation Mutex

提交回复
热议问题