Browse Source

Fixes a dispatcher bug that loses background processing state if jobs were submitted before ReplaceImplementation (#21735)

pull/21745/head
Nikita Tsukanov 3 months ago
committed by GitHub
parent
commit
fc9679491a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Base/Threading/Dispatcher.cs
  2. 32
      tests/Avalonia.Base.UnitTests/DispatcherTests.cs

3
src/Avalonia.Base/Threading/Dispatcher.cs

@ -162,6 +162,9 @@ public partial class Dispatcher : IDispatcher
_backgroundProcessingImpl.ReadyForBackgroundProcessing += OnReadyForExplicitBackgroundProcessing; _backgroundProcessingImpl.ReadyForBackgroundProcessing += OnReadyForExplicitBackgroundProcessing;
if (_signaled) if (_signaled)
_impl.Signal(); _impl.Signal();
if (_explicitBackgroundProcessingRequested)
_backgroundProcessingImpl?.RequestBackgroundProcessing();
_osTimerSetTo = null; _osTimerSetTo = null;
UpdateOSTimer(); UpdateOSTimer();
} }

32
tests/Avalonia.Base.UnitTests/DispatcherTests.cs

@ -151,6 +151,38 @@ public partial class DispatcherTests
Assert.Equal(new[] { "PromotedRender", "PromotedRender2", "Render" }, actions); Assert.Equal(new[] { "PromotedRender", "PromotedRender2", "Render" }, actions);
} }
[Fact]
public void DispatcherRepeatsBackgroundProcessingRequestToTheNewImplementation()
{
var actions = new List<string>();
// Requests background processing from the pre-initialization implementation
_uiThread.Post(() => actions.Add("Background"), DispatcherPriority.Background);
var impl = new SimpleDispatcherWithBackgroundProcessingImpl();
Dispatcher.InitializeUIThreadDispatcher(impl);
Assert.True(impl.AskedForBackgroundProcessing);
impl.FireBackgroundProcessing();
Assert.Equal(new[] { "Background" }, actions);
}
[Fact]
public void DispatcherRepeatsSignalToTheNewImplementation()
{
var actions = new List<string>();
// Signals the pre-initialization implementation
_uiThread.Post(() => actions.Add("Render"), DispatcherPriority.Render);
var impl = new SimpleDispatcherWithBackgroundProcessingImpl();
Dispatcher.InitializeUIThreadDispatcher(impl);
Assert.True(impl.AskedForSignal);
impl.ExecuteSignal();
Assert.Equal(new[] { "Render" }, actions);
}
[Fact] [Fact]
public void DispatcherStopsItemProcessingWhenInteractivityDeadlineIsReached() public void DispatcherStopsItemProcessingWhenInteractivityDeadlineIsReached()
{ {

Loading…
Cancel
Save