Requires: Synchronization between processes that does not suffer from AbandonedMutexException

I have several threads that acquire mutexes and then terminate.

Mutexes are stored in the main repository and correctly released when the program exists. However, when the thread that Mutex allocates exists, mutex is automatically freed and then throws an AbandonedMutexException (also as per the documentation ).

How can I avoid this exception and continue to use Mutex even after thread allocation is complete? Is there another, more appropriate synchronization construct in .Net that does not have this limitation.

Note . I am looking for a cross-process synchronization mechanism with similar semantics for Mutex.

+3
source share
3 answers

It looks like EventWaitHandle is doing what I want. It has a constructor that takes a name, so it is perfect for the cross-synchronization process, and it does not have this problem.

+1
source

Answer to the question

AFAIK there is no such mutex class. The AbandonedMutex exception is very annoying, but it is a real situation that can happen for which there is no automatic solution.

, , . Mutex , , Mutex, , . , , , .

The AbandonedMutexException - " , ". .

EventWaitHandle , Mutex .

Mutex , . , , Mutex. . , , Mutex, thread.s

EventWaitHandle , - , , . unsignaled, , . , .

EventWaitHandle . , , , , , . , .

  • ? ", ", , . EventWaitHandle , .
  • , - taskmgr? , , EventWaitHandle?
  • 2, , , , ? , .

+6

Mutex AbandonedMutexException. doc:

, , .

, , , ( ) , , , , .

, EvenWaitHandle , .

0

Source: https://habr.com/ru/post/1704889/


All Articles