Skip to main content

CompositeDisposable

A class in Alta.LifecycleManagement.Runtime, Alta.LifecycleManagement.

Thread-safe group of disposables that are disposed together. Anything added after it's disposed is disposed at once.

  • Listed in Other Alta assemblies
  • Inherits or implements ICollection<IDisposable>, IEnumerable<IDisposable>, IEnumerable, IDisposable, ICancelable
  • Attributes Preserve, UsedImplicitly

Constructors​

MemberWhat it is
CompositeDisposable()Creates a CompositeDisposable from disposables.
CompositeDisposable(int capacity)Creates a CompositeDisposable from disposables.
CompositeDisposable(params IDisposable[] disposables)Creates a CompositeDisposable from disposables.
CompositeDisposable(IEnumerable<IDisposable> disposables)Creates a CompositeDisposable from disposables.

Fields​

5 private and internal fields
MemberWhat it is
private int _countNumber of held disposables.
private List<IDisposable> _disposablesThe held disposables; removed slots are null until the list shrinks.
private bool _disposedBacking field for IsDisposed.
private readonly object _gateLock object.
private const int SHRINK_THRESHOLDList capacity above which removing items shrinks the list.

Properties​

MemberWhat it is
int Count { get; }How many disposables are held.
bool IsDisposed { get; }Whether Dispose has been called.
bool IsReadOnly { get; }Always false.

Methods​

MemberWhat it is
void Add(IDisposable item)Adds a disposable, or disposes it straight away if the group is already disposed.
void Clear()Disposes and removes everything, but the group stays usable.
bool Contains(IDisposable item)Whether the group holds the disposable.
void CopyTo(IDisposable[] array, int arrayIndex)Copies the held disposables into an array.
void Dispose()Disposes everything and marks the group disposed.
IEnumerator<IDisposable> GetEnumerator()Enumerates a snapshot of the held disposables.
bool Remove(IDisposable item)Removes and disposes a disposable. Returns false if it wasn't in the group.
1 private and internal method
MemberWhat it is
private IEnumerator System.Collections.IEnumerable.GetEnumerator()Enumerates a snapshot of the held disposables.