Why doesn't Mutex get released when disposed?

后端 未结 9 1184
青春惊慌失措
青春惊慌失措 2020-11-29 02:22

I have the following code:

using (Mutex mut = new Mutex(false, MUTEX_NAME))
{
    if (mut.WaitOne(new TimeSpan(0, 0, 30)))
    {
       // Some code that dea         


        
9条回答
  •  青春惊慌失措
    2020-11-29 02:39

    If you need to garantee that the mutex is released switch to a try catch finally block and put the mutex release in the finally block. It is assumed that you own and have a handle for the mutex. That logic needs to be included before release is invoked.

提交回复
热议问题