public void TestBusyLockObject() { BusyBO busy = new BusyBO(); busy.MarkBusy(true); using (BusyLocker bl = new BusyLocker(busy, TimeSpan.FromSeconds(1))) { System.ComponentModel.BackgroundWorker worker = new System.ComponentModel.BackgroundWorker(); worker.DoWork += (o, e) => busy.MarkBusy(false); worker.RunWorkerAsync(); } Assert.IsFalse(busy.IsBusy); }
public void SimpleLock() { BusyBO busy = new BusyBO(); busy.MarkBusy(true); System.ComponentModel.BackgroundWorker worker = new System.ComponentModel.BackgroundWorker(); worker.DoWork += (o, e) => { System.Threading.Thread.Sleep(10); busy.MarkBusy(false); }; worker.RunWorkerAsync(); BusyLock.WaitOne(busy); Assert.IsFalse(busy.IsBusy); }
public void TestTimeout() { BusyBO busy = new BusyBO(); busy.MarkBusy(true); BusyLock.WaitOne(busy, TimeSpan.FromMilliseconds(10)); Assert.IsTrue(busy.IsBusy); }