Removed leftover DispatcherHelper usages

This commit is contained in:
Sergio Pedri 2020-12-03 20:18:36 +01:00
Родитель 54c7c8c4dd
Коммит 92407a0fc3
7 изменённых файлов: 16 добавлений и 24 удалений

Просмотреть файл

@ -3,10 +3,9 @@
// See the LICENSE file in the project root for more information.
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.Extensions;
using Windows.System;
using Windows.UI.Xaml;
using Microsoft.Toolkit.Uwp.Extensions;
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{

Просмотреть файл

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.Extensions;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.SampleApp.Pages;
using Microsoft.Toolkit.Uwp.UI.Animations;
@ -147,7 +148,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
ShowSamplePicker(category.Samples, true);
// Then Focus on Picker
DispatcherHelper.ExecuteOnUIThreadAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard));
dispatcherQueue.EnqueueAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard));
}
}
else if (args.IsSettingsInvoked)

Просмотреть файл

@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Linq;
using Microsoft.Toolkit.Uwp.Extensions;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.UI.Xaml;
@ -76,7 +77,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
if (e.Key == Windows.System.VirtualKey.Down && SamplePickerGrid.Visibility == Windows.UI.Xaml.Visibility.Visible)
{
// If we try and navigate down out of the textbox (and there's search results), go to the search results.
DispatcherHelper.ExecuteOnUIThreadAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard));
dispatcherQueue.EnqueueAsync(() => SamplePickerGridView.Focus(FocusState.Keyboard));
}
}

Просмотреть файл

@ -7,7 +7,6 @@ using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.SampleApp.Pages;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;
@ -16,6 +15,8 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
{
public sealed partial class Shell
{
private readonly DispatcherQueue dispatcherQueue = DispatcherQueue.GetForCurrentThread();
public static Shell Current { get; private set; }
public Shell()

Просмотреть файл

@ -6,7 +6,7 @@ using System;
using System.Collections.Generic;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.Extensions;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Composition.Effects;
@ -102,7 +102,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
var task = new AnimationTask();
task.AnimationSet = animationSet;
task.Task = DispatcherHelper.ExecuteOnUIThreadAsync(
task.Task = visual.DispatcherQueue.EnqueueAsync(
() =>
{
const string sceneName = "PointLightScene";
@ -184,7 +184,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations
}
pointLights[visual] = pointLight;
}, Windows.UI.Core.CoreDispatcherPriority.Normal);
});
animationSet.AddAnimationThroughTask(task);
return animationSet;

Просмотреть файл

@ -162,10 +162,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
offsetX = offsetX > _maxSpeed ? _maxSpeed : offsetX;
offsetY = offsetY > _maxSpeed ? _maxSpeed : offsetY;
RunInUIThread(dispatcherQueue, () =>
{
_scrollViewer?.ChangeView(_scrollViewer.HorizontalOffset + offsetX, _scrollViewer.VerticalOffset + offsetY, null, true);
});
dispatcherQueue.EnqueueAsync(() => _scrollViewer?.ChangeView(_scrollViewer.HorizontalOffset + offsetX, _scrollViewer.VerticalOffset + offsetY, null, true));
}
}
@ -326,10 +323,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
if (_oldCursorID != cursorID)
{
RunInUIThread(dispatcherQueue, () =>
{
Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Custom, cursorID);
});
dispatcherQueue.EnqueueAsync(() => Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Custom, cursorID));
_oldCursorID = cursorID;
}
@ -366,10 +360,5 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
return isCursorAvailable;
}
private static async void RunInUIThread(DispatcherQueue dispatcherQueue, Action action)
{
await dispatcherQueue.EnqueueAsync(action, DispatcherQueuePriority.Normal);
}
}
}

Просмотреть файл

@ -4,6 +4,7 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.Extensions;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -21,7 +22,7 @@ namespace UnitTests.XamlIslands.UWPApp
[TestInitialize]
public async Task Init()
{
await App.Dispatcher.ExecuteOnUIThreadAsync(() =>
await App.Dispatcher.EnqueueAsync(() =>
{
var xamlItemsPanelTemplate = @"<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
@ -65,7 +66,7 @@ namespace UnitTests.XamlIslands.UWPApp
[TestCleanup]
public async Task Cleanup()
{
await App.Dispatcher.ExecuteOnUIThreadAsync(() =>
await App.Dispatcher.EnqueueAsync(() =>
{
GazeInput.SetInteraction(_grid, Interaction.Disabled);
});
@ -76,7 +77,7 @@ namespace UnitTests.XamlIslands.UWPApp
[Ignore]
public async Task Gaze_DoesNotCrashOnIslands()
{
await App.Dispatcher.ExecuteOnUIThreadAsync(async () =>
await App.Dispatcher.EnqueueAsync(async () =>
{
await Task.Delay(10000);