Mutex not releasing

前端 未结 2 732
生来不讨喜
生来不讨喜 2021-01-22 14:45

My c# WinForm solution contains several projects including an Admin project containing frmAdmin and a User project containing frmUser. A third project contains frmTimer that ha

2条回答
  •  我在风中等你
    2021-01-22 14:52

    The problem is that once you run the admin application the Mutex exists and then the OpenExisting succeeds. Releasing a Mutex does not destroy the Kernel object, it just releases the hold on the mutex so that other waiting threads can execute. Therefore susequent Mutex.OpenExisting calls open the mutex successfully.

    You probably want to use Mutex.WaitOne(TimeSpan) if you successfully open the Mutex and if WaitOne returns false then you know you you could not acquire the mutex so the Admin application still hold the mutex.

提交回复
热议问题