/// <summary> /// Requests the purge of the inactive listeners. /// </summary> /// <param name="threshold">The collection count threshold.</param> private void ScheduleCleanup(int threshold) { if (ValueSafe.LessExchange(ref gen1, int.MaxValue, threshold) < threshold) { Async.Start(Cleanup, source); } }
/// <summary> /// Throws an exception if the <see cref="PropertyObserver"/> is disposed. /// </summary> private void CheckDisposed() { if (ValueSafe.Equals1(ref disposed)) { throw Error.ObjectDisposed(this); } }
/// <summary> /// Marks the event for cancellation. /// </summary> public void Cancel() { if (CanCancel) { ValueSafe.Increment0(ref canceled); return; } throw Error.InvalidOperation(Strings.NotCancelable); }
/// <summary> /// Releases resources used by the <see cref="PropertyObserver"/>. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing && ValueSafe.Increment0(ref disposed)) { lock (table) { foreach (KeyValuePair <INotifyPropertyChanged, Subscriber> pair in table) { Subscriber subscriber = pair.Value; subscriber.Dispose(); PropertyChangedEvent.RemoveListener(pair.Key, subscriber); } table.Clear(); } } }