forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update DispatcherHelper to winui3/release/1.4.2
- Loading branch information
1 parent
bf63591
commit 99e91bd
Showing
2 changed files
with
30 additions
and
98 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
// MUX Reference DispatcherHelper.h, tag winui3/release/1.4.2 | ||
|
||
using System; | ||
using Windows.UI.Xaml; | ||
|
||
namespace Uno.UI.Helpers.WinUI; | ||
|
||
internal class DispatcherHelper | ||
{ | ||
private Windows.System.DispatcherQueue dispatcherQueue; | ||
|
||
public DispatcherHelper(DependencyObject dependencyObject = null) | ||
{ | ||
dispatcherQueue = Windows.System.DispatcherQueue.GetForCurrentThread(); | ||
} | ||
|
||
public void RunAsync(Action func, bool fallbackToThisThread = false) | ||
{ | ||
var result = dispatcherQueue?.TryEnqueue(() => func()) ?? false; | ||
if (!result) | ||
{ | ||
if (fallbackToThisThread) | ||
{ | ||
func(); | ||
} | ||
} | ||
} | ||
} |