If the collection is small, then you can periodically make it a dump and display it in the GUI instead of the original collection.
I sketched this example: the original collection is filled with a timer every 20 ms, a dump is created every 100 ms:
class MainVm : Vm { public ICommand StartUpdatingCommand { get; } public ICommand StopUpdatingCommand { get; } CancellationTokenSource cancellationTokenSource; public ObservableCollection<int> Collection { get; } IEnumerable<int> collectionDump; public IEnumerable<int> CollectionDump { get => collectionDump; set => Set(ref collectionDump, value, nameof(CollectionDump)); } public MainVm() { StartUpdatingCommand = new DelegateCommand(_ => StartUpdating()); StopUpdatingCommand = new DelegateCommand(_ => StopUpdating()); Collection = new ObservableCollection<int>(); CollectionDump = Collection.ToArray(); var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(20) }; timer.Tick += delegate { Collection.Add(10); Collection.Add(20); if (Collection.Count > 100) Collection.Clear(); }; timer.Start(); } private async void StartUpdating() { if (cancellationTokenSource != null) return; cancellationTokenSource = new CancellationTokenSource(); try { while (!cancellationTokenSource.IsCancellationRequested) { CollectionDump = Collection.ToArray(); await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationTokenSource.Token); } } catch (OperationCanceledException) { } finally { cancellationTokenSource = null; } } private void StopUpdating() { cancellationTokenSource?.Cancel(); } }
Marking the contents of the window:
<Grid Margin="5"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <ListBox ItemsSource="{Binding CollectionDump}"/> <UniformGrid Grid.Row="1" Margin="0,5,0,0" HorizontalAlignment="Center" Rows="1"> <UniformGrid.Resources> <Style TargetType="Button"> <Setter Property="Padding" Value="10,2"/> <Setter Property="Margin" Value="2.5"/> </Style> </UniformGrid.Resources> <Button Content="Start updating" Command="{Binding StartUpdatingCommand}"/> <Button Content="Stop updating" Command="{Binding StopUpdatingCommand}"/> </UniformGrid> </Grid>
Pay attention, binding it to CollectionDump
List2 = List1.ToList(), whereList1is your rapidly changing collection, andList2is a new collection that is tied in the GUI - Andrey NOP