public delegate void FuncRO <T1, T2>(ref T1 arg1, out T2 arg2); public static void LockedCall <T1, T2>(string name, FuncRO <T1, T2> func, ref T1 arg1, out T2 arg2) { while (true) { try { var mutex = new Mutex(false, name); mutex.WaitOne(); func(ref arg1, out arg2); mutex.ReleaseMutex(); } catch (AbandonedMutexException) { } } }
public delegate U FuncRO <T1, T2, U>(ref T1 arg1, out T2 arg2); public static U LockedCall <T1, T2, U>(string name, FuncRO <T1, T2, U> func, ref T1 arg1, out T2 arg2) { while (true) { try { var mutex = new Mutex(false, name); mutex.WaitOne(); U result = func(ref arg1, out arg2); mutex.ReleaseMutex(); return(result); } catch (AbandonedMutexException) { } } }