Skip to content

Commit

Permalink
fix: ScheduleActionAfterWait should not use DispatcherHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 5, 2023
1 parent 99e91bd commit 702f9b5
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/Uno.UI/Helpers/WinUI/SharedHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,6 @@ public static bool IsStandardUICommandAvailable()
return s_IsStandardUICommandAvailable_isAvailable.Value;
}

static bool? s_IsDispatcherQueueAvailable_isAvailable;
public static bool IsDispatcherQueueAvailable()
{
if (s_IsDispatcherQueueAvailable_isAvailable == null)
{
s_IsDispatcherQueueAvailable_isAvailable =
IsSystemDll() ||
IsRS4OrHigher() ||
ApiInformation.IsTypePresent("Windows.System.DispatcherQueue");
}

return s_IsDispatcherQueueAvailable_isAvailable.Value;
}

static bool? s_IsXamlRootAvailable;
public static bool IsXamlRootAvailable()
{
Expand Down Expand Up @@ -543,17 +529,19 @@ public static void ScheduleActionAfterWait(
Action action,
uint millisecondWait)
{
// The callback that is given to CreateTimer is called off of the UI thread.
// In order to make this useful by making it so we can interact with XAML objects,
// we'll use the dispatcher to first post our work to the UI thread before executing it.
ThreadPoolTimer.CreateTimer(t =>
if (DispatcherQueue.GetForCurrentThread() is { } dispatcherQueue)
{
// The callback that is given to CreateTimer is called off of the UI thread.
// In order to make this useful by making it so we can interact with XAML objects,
// we'll use the dispatcher to first post our work to the UI thread before executing it.
ThreadPoolTimer.CreateTimer(t =>
{
new DispatcherHelper().RunAsync(action);
dispatcherQueue.TryEnqueue(new DispatcherQueueHandler(action));
},
TimeSpan.FromMilliseconds(millisecondWait));
}
}


// Stream helpers
//InMemoryRandomAccessStream CreateStreamFromBytes(const array_view<const byte>& bytes)
//{
Expand Down

0 comments on commit 702f9b5

Please sign in to comment.