@@ -295,34 +295,32 @@ public class ResultCollection : List<ResultViewModel>, INotifyCollectionChanged
295295 {
296296 private long editTime = 0 ;
297297
298- private CancellationToken _token ;
299-
300298 public event NotifyCollectionChangedEventHandler CollectionChanged ;
301299
302300 protected void OnCollectionChanged ( NotifyCollectionChangedEventArgs e )
303301 {
304302 CollectionChanged ? . Invoke ( this , e ) ;
305303 }
306304
307- public void BulkAddAll ( List < ResultViewModel > resultViews )
305+ private void BulkAddAll ( List < ResultViewModel > resultViews , CancellationToken token = default )
308306 {
309307 AddRange ( resultViews ) ;
310308
311309 // can return because the list will be cleared next time updated, which include a reset event
312- if ( _token . IsCancellationRequested )
310+ if ( token . IsCancellationRequested )
313311 return ;
314312
315313 // manually update event
316314 // wpf use DirectX / double buffered already, so just reset all won't cause ui flickering
317315 OnCollectionChanged ( new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Reset ) ) ;
318316 }
319317
320- private void AddAll ( List < ResultViewModel > Items )
318+ private void AddAll ( List < ResultViewModel > Items , CancellationToken token = default )
321319 {
322320 for ( int i = 0 ; i < Items . Count ; i ++ )
323321 {
324322 var item = Items [ i ] ;
325- if ( _token . IsCancellationRequested )
323+ if ( token . IsCancellationRequested )
326324 return ;
327325 Add ( item ) ;
328326 OnCollectionChanged ( new NotifyCollectionChangedEventArgs ( NotifyCollectionChangedAction . Add , item , i ) ) ;
@@ -344,35 +342,30 @@ public void RemoveAll(int Capacity = 512)
344342 /// <param name="newItems"></param>
345343 public void Update ( List < ResultViewModel > newItems , CancellationToken token = default )
346344 {
347- _token = token ;
348-
349345 // Since NewResults may need to clear existing results, so we cannot check token cancellation here
350346 if ( Count == 0 && newItems . Count == 0 )
351347 return ;
352348
353349 if ( editTime < 10 || newItems . Count < 30 )
354350 {
355- // RemoveAll will not check token cancellation, so it will clear existing results
356351 if ( Count != 0 ) RemoveAll ( newItems . Count ) ;
357352
358353 // After results are removed, we need to check the token cancellation
359354 // so that we will not add new items from the cancelled queries
360355 if ( token . IsCancellationRequested ) return ;
361356
362- AddAll ( newItems ) ;
357+ AddAll ( newItems , token ) ;
363358 editTime ++ ;
364- return ;
365359 }
366360 else
367361 {
368- // Clear will not check token cancellation, so it will clear existing results
369362 Clear ( ) ;
370363
371364 // After results are removed, we need to check the token cancellation
372365 // so that we will not add new items from the cancelled queries
373366 if ( token . IsCancellationRequested ) return ;
374367
375- BulkAddAll ( newItems ) ;
368+ BulkAddAll ( newItems , token ) ;
376369 if ( Capacity > 8000 && newItems . Count < 3000 )
377370 {
378371 Capacity = newItems . Count ;
0 commit comments