我对 ReaderWriterLockSlim 和延迟 ExitWriteLock 感到沮丧。为什么定时器回调中释放了WriteLock?
var _lock = new ReaderWriterLockSlim();
_lock.EnterWriteLock();
Assert.AreEqual(true, _lock.IsWriteLockHeld); // good
System.Threading.Timer timer = new Timer(state =>
{
_lock.ExitWriteLock(); //throws exception that lock is not held
}, null, 1, -1);
Thread.Sleep(1000);
Assert.AreEqual(false, _lock.IsWriteLockHeld);