Browse Source

Fixed dispatcher frame capturing wrong dispatcher (#22086)

pull/22095/head
Nikita Tsukanov 1 month ago
committed by GitHub
parent
commit
3b259812c4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      src/Avalonia.Base/Threading/DispatcherFrame.cs
  2. 15
      tests/Avalonia.Base.UnitTests/DispatcherTests.cs

4
src/Avalonia.Base/Threading/DispatcherFrame.cs

@ -38,7 +38,7 @@ public class DispatcherFrame
/// for their important criteria to be met. These frames
/// should have a timeout associated with them.
/// </param>
public DispatcherFrame(bool exitWhenRequested) : this(Dispatcher.UIThread, exitWhenRequested)
public DispatcherFrame(bool exitWhenRequested) : this(Dispatcher.CurrentDispatcher, exitWhenRequested)
{
Dispatcher.VerifyAccess();
}
@ -139,4 +139,4 @@ public class DispatcherFrame
if (_exitWhenRequested)
_cancellationTokenSource?.Cancel();
}
}
}

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

@ -317,6 +317,21 @@ public partial class DispatcherTests
}
}
[Fact]
public async Task DispatcherFrame_Uses_Current_Dispatcher()
{
var uiThreadDispatcher = Dispatcher.UIThread;
await ThreadRunHelper.RunOnDedicatedThread(() =>
{
var currentDispatcher = Dispatcher.CurrentDispatcher;
var frame = new DispatcherFrame();
Assert.NotSame(uiThreadDispatcher, currentDispatcher);
Assert.Same(currentDispatcher, frame.Dispatcher);
});
}
[Fact]
public void ExitAllFramesShouldExitAllFramesAndBeAbleToContinue()
{

Loading…
Cancel
Save