Class BatchObservableCollection<T>
An ObservableCollection<T> that suppresses all notifications during a batch, then fires a single coalesced notification when the batch ends.
Inherited Members
Namespace: MOSAIC.Visualization.ScopeMonitor
Assembly: MOSAIC.dll
Syntax
public class BatchObservableCollection<T> : ObservableCollection<T>, IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
The notification strategy matters critically for LiveCharts2's VectorManager.
A CollectionChanged(Reset) notification causes LiveCharts to fully re-initialise
its internal segment bookkeeping on the next Measure() pass. If a second
Measure() is already queued (via UpdateThrottlerUnlocked), the two
passes share a VectorManager whose state is half-rebuilt, triggering
AddConsecutiveSegment to throw "This should not happen :(".
The safe strategy: when the batch ends after a Clear(), fire nothing
if the collection is empty — there are no segments for VectorManager to track,
so there is no state to corrupt. LiveCharts will read the empty collection on its next
naturally-scheduled Measure() and produce a blank frame cleanly.
When the batch ends with data, fire a single Reset as before — this is safe
because the VectorManager has valid points to work with.
Additionally, if IsChartReady is false (chart not yet attached or
being destroyed), all notifications are suppressed unconditionally. Set this to
true only from NotifyChartReady(), called after the chart's first
Measure() confirms VectorManager is initialised.
Fields
_suppressing
Declaration
private bool _suppressing
Field Value
| Type | Description |
|---|---|
| bool |
Properties
IsChartReady
When false (the default), all INotifyCollectionChanged and
INotifyPropertyChanged notifications are suppressed unconditionally.
Set to true only after the bound chart's first Measure() pass has
confirmed VectorManager is ready to receive segment updates.
Declaration
public bool IsChartReady { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
BeginBatch()
Begins a batch — all mutations are suppressed until EndBatch().
Declaration
public void BeginBatch()
EndBatch()
Ends the batch. If IsChartReady is false, or the collection is empty
after the batch, no notification is fired. Otherwise fires a single Reset.
Declaration
public void EndBatch()
Remarks
Firing Reset on an empty collection is the trigger for the VectorManager crash:
it causes LiveCharts to attempt a full re-layout with zero segments, which corrupts
the segment linked-list and makes the next Measure() throw.
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Raises the CollectionChanged event with the provided arguments.
Declaration
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| NotifyCollectionChangedEventArgs | e | Arguments of the event being raised. |
Overrides
OnPropertyChanged(PropertyChangedEventArgs)
Raises the PropertyChanged event with the provided arguments.
Declaration
protected override void OnPropertyChanged(PropertyChangedEventArgs e)
Parameters
| Type | Name | Description |
|---|---|---|
| PropertyChangedEventArgs | e | Arguments of the event being raised. |