예제 #1
0
 /// <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);
     }
 }
예제 #2
0
 /// <summary>
 /// Throws an exception if the <see cref="PropertyObserver"/> is disposed.
 /// </summary>
 private void CheckDisposed()
 {
     if (ValueSafe.Equals1(ref disposed))
     {
         throw Error.ObjectDisposed(this);
     }
 }
예제 #3
0
        /// <summary>
        /// Marks the event for cancellation.
        /// </summary>
        public void Cancel()
        {
            if (CanCancel)
            {
                ValueSafe.Increment0(ref canceled);

                return;
            }

            throw Error.InvalidOperation(Strings.NotCancelable);
        }
예제 #4
0
        /// <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();
                }
            }
        }