Skip to content

Commit

Permalink
fix: Fix WaitForIdle in UWP to really wait for "Idle"
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Dec 20, 2023
1 parent 6c3ce9e commit c59ce5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ internal set
/// <returns></returns>
public static async Task WaitForIdle()
{
#if WINDOWS_WINUI || HAS_UNO_WINUI
// This is a wrong implementation. It doesn't really wait for "Idle".
await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Low, () => { });
await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Low, () => { });
#else
await RootElementDispatcher.RunIdleAsync(_ => { /* Empty to wait for the idle queue to be reached */ });
await RootElementDispatcher.RunIdleAsync(_ => { /* Empty to wait for the idle queue to be reached */ });
#endif
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public enum Priority { Low = -1, Normal = 0, High = 1 }

private static _Priority RemapPriority(Priority priority) => priority switch
{
// [uwp] Windows.UI.Core.CoreDispatcherPriority::Idle doesnt have a counterpart, and is thus ignored.
// [uwp] Windows.UI.Core.CoreDispatcherPriority::Idle doesnt have a counterpart, and is thus ignored.

Priority.Low => _Priority.Low,
Priority.Low => _Priority.Low,
Priority.Normal => _Priority.Normal,
Priority.High => _Priority.High,

Expand All @@ -53,7 +53,12 @@ public UnitTestDispatcherCompat(_Impl impl)
this._impl = impl;
}

public static UnitTestDispatcherCompat From(UIElement x) =>
#if !WINDOWS_WINUI && !HAS_UNO_WINUI
public Windows.Foundation.IAsyncAction RunIdleAsync(Windows.UI.Core.IdleDispatchedHandler agileCallback)
=> _impl.RunIdleAsync(agileCallback);
#endif

public static UnitTestDispatcherCompat From(UIElement x) =>
#if HAS_UNO_WINUI || WINDOWS_WINUI
new UnitTestDispatcherCompat(x.DispatcherQueue);
#else
Expand Down

0 comments on commit c59ce5a

Please sign in to comment.