Skip to content

ReferenceBehavior of every data source

Behavior of every data source

Every data source, combinator and provider side by side: who disposes what, what signals a change, whether it rebuilds, its thread safety, what disposal does and how errors reach you.

The matrix below and Which data source? are drawn from one data file, so they agree. Each name links its card on that page, and each row ends with the page that explains it.

Data sourceWho disposes whatWhat signals a changeRebuild or diffThread safetyWhat disposal doesHow errors reach youExplained on
CreateStaticNever disposes the collection it is given; disposes each item that implements IDisposable only with disposeItems: true.Never: its token is NullChangeToken.Singleton, and disposal doesn't signal it either.Neither: it copies the items once, at construction.A snapshot that never changes, safe to read from any thread.Disposes the items when disposeItems is true. Then Collection throws ObjectDisposedException.Construction copies the items, so an enumeration that throws reaches the caller of CreateStatic.Combine data sources
CreateObservableNever disposes the ObservableCollection<T>; disposes each item that implements IDisposable only with disposeItems: true.Every CollectionChanged event of the collection.Copies every item into a new snapshot on each change, under its lock, before it signals.Reads are safe from any thread. The ObservableCollection<T> is not: edit it from one thread at a time.Stops listening to CollectionChanged, disposes the items when disposeItems is true, then signals once.An exception from a consumer's change callback is dropped, so an edit of the collection never throws it.Combine data sources
CreateMutableNever disposes its items, which a reader may still hold in an older snapshot.Each call of Replace, Update or Add, and each call of AddRange, Remove or Clear that changes the items: one signal per call.Swaps in a new immutable snapshot under its lock on each call that changes the items.Every member is safe from any thread, and Update's function runs under the source's lock.Drops the items without disposing them, then signals once.An Update function or an enumeration that throws reaches the caller and leaves the items as they were.Push or reload items
CreateChangeTokenNever disposes its items, which a reader may still hold in an older snapshot.After each reload its producer's token triggers. A signal before the first load only renews the token, and once reloading ends it never signals again.Calls load again and copies the result into a new snapshot, under its lock.Reads are safe from any thread. A reload runs under the source's lock, on the thread that fired the token.Stops listening and drops the items, then signals once.The first load's exception reaches the reader. A later reload's goes to handleException, and the source keeps its last items; without a handler, or when it throws, reloading ends.Push or reload items
CreateCompositeDisposes the sources it is given unless owns is false, and never disposes an extra change token producer.After it rebuilds, when any source or extra change token producer signals.Runs CombineFunc over every source's whole collection again, concatenation in source order by default.Reads take no lock. Rebuilds run one at a time under its lock, on the thread that signalled.Disposes the sources it owns, then signals once.A CombineFunc or a source that throws on the first read throws to the reader. On a rebuild the exception is dropped, and the composite keeps its last items.Combine data sources
CreatePeriodicPollingOwns neither its state nor its items.A refresh, by the timer or by RefreshAsync, that returns Changed.Neither: it stores the collection a Changed result carries, as it is.Reads are safe from any thread, and refreshes run one at a time. Never change a collection after handing it over.Dispose cancels polling and returns without waiting for a running refresh; DisposeAsync also waits for the polling loop to end. Then it signals once.A timer refresh's exception goes to the HandleExceptionCallback, whose default rethrows and ends polling. A RefreshAsync refresh's goes to its caller.Poll a remote source
TransformDisposes its source unless owns is false.After it rebuilds, each time its source signals.Runs the function over the source's whole collection again, into an immutable snapshot.Reads take no lock. A rebuild runs under its lock, on the thread that signalled.Ends its subscription and disposes its source when it owns it, then signals once.A function that throws on the first read throws to the reader. On a rebuild the exception is dropped, and the source keeps its last items.Derive a data source
SelectItemsDisposes its source unless owns is false.After it rebuilds, each time its source signals.Maps every item of the source again, into an immutable snapshot.Reads take no lock. A rebuild runs under its lock, on the thread that signalled.Ends its subscription and disposes its source when it owns it, then signals once.A selector that throws on the first read throws to the reader. On a rebuild the exception is dropped, and the source keeps its last items.Derive a data source
WhereItemsDisposes its source unless owns is false.After it rebuilds, each time its source signals.Tests every item of the source again, into an immutable snapshot.Reads take no lock. A rebuild runs under its lock, on the thread that signalled.Ends its subscription and disposes its source when it owns it, then signals once.A predicate that throws on the first read throws to the reader. On a rebuild the exception is dropped, and the source keeps its last items.Derive a data source
ConcatSourcesDisposes every source it joins unless owns is false.After it rebuilds, when any of its sources signals.Concatenates every source's whole collection again, the receiver first.Reads take no lock. Rebuilds run one at a time under its lock, on the thread that signalled.Disposes the sources it owns, then signals once.A source that throws on the first read throws to the reader. On a rebuild the exception is dropped, and the last items stay.Derive a data source
DebounceDisposes its source unless owns is false.Once, after its source has been quiet for quietPeriod.Neither: at the end of a quiet period it reads its source's Collection once and hands out that snapshot.Reads are safe from any thread. The read of its source and its signal run on the timer's thread.Drops a pending signal and disposes its source when it owns it, then signals once.A failure of the first read throws to the reader. A read that throws at the end of a quiet period is dropped, and the collection from before stays.React to changes
ICollectionProviderFactory.CreateDisposes the data sources it is given unless owns is false, and never disposes an extra change token producer.After each rebuild, when any data source or extra change token producer signals.Calls the collection factory with every source's whole collection: one full rebuild per signal, never a diff.Reads take no lock. The first build and every rebuild run one at a time under its lock, on the thread that signalled.Disposes its subscriptions and the sources it owns, then signals once. Then Collection throws ObjectDisposedException.A failure of the first build throws to the reader. A collection factory that throws on a rebuild is dropped, and the provider keeps its previous collection.Combine data sources
  • Who disposes what: owns decides whether a provider, a composite or a derived source disposes the sources it is given, and disposeItems whether a static or observable source disposes its items. Data sources and ownership has the rules.
  • What signals a change: each source hands out an IChangeToken that signals once, and a consumer asks for a fresh one after it does. How a provider rebuilds follows one signal.
  • Rebuild or diff: nothing applies a diff. A provider, a composite, ConcatSources, Transform, SelectItems and WhereItems build their collection again in full on each signal. A full rebuild says what that costs.
  • Thread safety: every built-in source and every provider hands out a snapshot that never changes, so reads are safe from any thread, and rebuilds run one at a time. Reads and the lock explains the lock.
  • What disposal does: disposing a provider or a built-in source signals the change token it handed out once, last, and later reads throw ObjectDisposedException; the static source’s token never signals. Own and dispose shows it.
  • How errors reach you: an exception from a consumer’s change callback never reaches the source that signalled. A failed refresh or reload goes to its handler, as periodic polling and keep reloading through a failure say.