@@ -455,7 +455,10 @@ private void ProcessRenderQueue()
455
455
}
456
456
finally
457
457
{
458
- RemoveEventHandlerIds ( _batchBuilder . DisposedEventHandlerIds . ToRange ( ) , updateDisplayTask ) ;
458
+ // RemoveEventHandlerIdsAsync is designed to be fired-and-forgotten
459
+ // It will clone and persist any state it needs if it needs to run asynchronously
460
+ _ = RemoveEventHandlerIdsAsync ( _batchBuilder . DisposedEventHandlerIds . ToRange ( ) , updateDisplayTask ) ;
461
+
459
462
_batchBuilder . ClearStateForCurrentBatch ( ) ;
460
463
_isBatchInProgress = false ;
461
464
}
@@ -599,14 +602,14 @@ private void RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
599
602
}
600
603
}
601
604
602
- private void RemoveEventHandlerIds ( ArrayRange < int > eventHandlerIds , Task afterTask )
605
+ private async Task RemoveEventHandlerIdsAsync ( ArrayRange < int > eventHandlerIds , Task afterTaskIgnoreErrors )
603
606
{
604
607
if ( eventHandlerIds . Count == 0 )
605
608
{
606
609
return ;
607
610
}
608
611
609
- if ( afterTask . IsCompleted )
612
+ if ( afterTaskIgnoreErrors . IsCompleted )
610
613
{
611
614
var array = eventHandlerIds . Array ;
612
615
var count = eventHandlerIds . Count ;
@@ -622,8 +625,19 @@ private void RemoveEventHandlerIds(ArrayRange<int> eventHandlerIds, Task afterTa
622
625
// any further). We must clone the data because the underlying RenderBatchBuilder
623
626
// may be reused and hence modified by an unrelated subsequent batch.
624
627
var eventHandlerIdsClone = eventHandlerIds . Clone ( ) ;
625
- afterTask . ContinueWith ( _ =>
626
- RemoveEventHandlerIds ( eventHandlerIdsClone , Task . CompletedTask ) ) ;
628
+
629
+ try
630
+ {
631
+ await afterTaskIgnoreErrors ;
632
+ }
633
+ catch ( Exception )
634
+ {
635
+ // As per method contract, we're not error-handling the task.
636
+ // That remains the caller's business.
637
+ }
638
+
639
+ // We know the next execution will complete synchronously, so nothing to await
640
+ _ = RemoveEventHandlerIdsAsync ( eventHandlerIdsClone , Task . CompletedTask ) ;
627
641
}
628
642
}
629
643
0 commit comments