abandonedmutexexception

How to gracefully get out of AbandonedMutexException?

好久不见. 提交于 2019-11-29 05:52:31
I use the following code to synchronize mutually exclusive access to a shared resource between several running processes. The mutex is created as such: Mutex mtx = new Mutex(false, "MyNamedMutexName"); Then I use this method to enter mutually exclusive section: public bool enterMutuallyExclusiveSection() { //RETURN: 'true' if entered OK, // can continue with mutually exclusive section bool bRes; try { bRes = mtx.WaitOne(); } catch (AbandonedMutexException) { //Abandoned mutex, how to handle it? //bRes = ? } catch { //Some other error bRes = false; } return bRes; } and this code to leave it:

How to gracefully get out of AbandonedMutexException?

烈酒焚心 提交于 2019-11-27 23:27:13
问题 I use the following code to synchronize mutually exclusive access to a shared resource between several running processes. The mutex is created as such: Mutex mtx = new Mutex(false, "MyNamedMutexName"); Then I use this method to enter mutually exclusive section: public bool enterMutuallyExclusiveSection() { //RETURN: 'true' if entered OK, // can continue with mutually exclusive section bool bRes; try { bRes = mtx.WaitOne(); } catch (AbandonedMutexException) { //Abandoned mutex, how to handle