public virtual void TestTryLock() { Assert.IsTrue(mm.TryLock("key1", 200, TimeUnit.Milliseconds)); var latch = new CountdownEvent(1); var t = new Thread(delegate(object o) { try { if (!mm.TryLock("key1", 200, TimeUnit.Milliseconds)) { latch.Signal(); } } catch { } }); t.Start(); Assert.IsTrue(latch.Wait(TimeSpan.FromSeconds(10))); Assert.IsTrue(mm.IsLocked("key1")); var latch2 = new CountdownEvent(1); var t2 = new Thread(delegate(object o) { try { if (mm.TryLock("key1", 20, TimeUnit.Seconds)) { latch2.Signal(); } } catch { } }); t2.Start(); Thread.Sleep(100); mm.Unlock("key1"); Assert.IsTrue(latch2.Wait(TimeSpan.FromSeconds(10))); Assert.IsTrue(mm.IsLocked("key1")); mm.ForceUnlock("key1"); }