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); }
/// <summary> /// Wait until the specified object is not busy /// (IsBusy is false). /// </summary> /// <param name="obj">Target object.</param> /// <param name="timeout">Timeout value.</param> public static void WaitOne(INotifyBusy obj, TimeSpan timeout) { BusyLocker locker = new BusyLocker(obj, timeout); locker.WaitOne(); }
/// <summary> /// Wait until the specified object is not busy /// (IsBusy is false). /// </summary> /// <param name="obj">Target object.</param> public static void WaitOne(INotifyBusy obj) { BusyLocker locker = new BusyLocker(obj, TimeSpan.FromMilliseconds(Timeout.Infinite)); locker.WaitOne(); }