From 336b1aa8baba2b22ba49d214de60cefe37d0ff4e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 14 Jul 2017 00:31:34 +0200 Subject: [PATCH] Minor refactoring --- .../AttachedCompositionEffectFactory.cs | 22 ++++++++--------- .../Helpers/DispatcherHelper.cs | 24 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/UICompositionAnimations/Behaviours/AttachedCompositionEffectFactory.cs b/UICompositionAnimations/Behaviours/AttachedCompositionEffectFactory.cs index ee2f88a..c25b384 100644 --- a/UICompositionAnimations/Behaviours/AttachedCompositionEffectFactory.cs +++ b/UICompositionAnimations/Behaviours/AttachedCompositionEffectFactory.cs @@ -429,7 +429,7 @@ public static async Task> AttachCompositi where T : FrameworkElement { // Get the compositor - Visual visual = await element.Dispatcher.GetFromUIThreadAsync(element.GetVisual); + Visual visual = await element.Dispatcher.GetAsync(element.GetVisual); Compositor compositor = visual.Compositor; // Create the saturation effect and the effect factory @@ -450,7 +450,7 @@ public static async Task> AttachCompositi SpriteVisual sprite = compositor.CreateSpriteVisual(); sprite.Brush = effectBrush; await AddToTreeAndBindSizeAsync(visual, element, sprite); - if (initiallyVisible) await element.Dispatcher.RunOnUIThreadAsync(() => element.Opacity = 1); + if (initiallyVisible) await element.Dispatcher.RunAsync(() => element.Opacity = 1); return new AttachedAnimatableCompositionEffect(element, sprite, new CompositionAnimationParameters(animationPropertyName, on, off), disposeOnUnload); } @@ -468,7 +468,7 @@ public static async Task> AttachCompositi [NotNull] this T element, float on, float off, bool initiallyVisible, bool disposeOnUnload = false) where T : FrameworkElement { // Get the compositor - Visual visual = await element.Dispatcher.GetFromUIThreadAsync(element.GetVisual); + Visual visual = await element.Dispatcher.GetAsync(element.GetVisual); Compositor compositor = visual.Compositor; // Create the blur effect and the effect factory @@ -491,7 +491,7 @@ public static async Task> AttachCompositi SpriteVisual sprite = compositor.CreateSpriteVisual(); sprite.Brush = effectBrush; await AddToTreeAndBindSizeAsync(visual, element, sprite); - if (initiallyVisible) await element.Dispatcher.RunOnUIThreadAsync(() => element.Opacity = 1); + if (initiallyVisible) await element.Dispatcher.RunAsync(() => element.Opacity = 1); return new AttachedAnimatableCompositionEffect(element, sprite, new CompositionAnimationParameters(animationPropertyName, on, off), disposeOnUnload); } @@ -522,7 +522,7 @@ public static async Task> AttachCompositi where T : FrameworkElement { // Get the compositor - Visual visual = await element.Dispatcher.GetFromUIThreadAsync(element.GetVisual); + Visual visual = await element.Dispatcher.GetAsync(element.GetVisual); Compositor compositor = visual.Compositor; // Create the blur effect and the effect factory @@ -561,7 +561,7 @@ public static async Task> AttachCompositi SpriteVisual sprite = compositor.CreateSpriteVisual(); sprite.Brush = effectBrush; await AddToTreeAndBindSizeAsync(target.GetVisual(), target, sprite); - if (initiallyVisible) await element.Dispatcher.RunOnUIThreadAsync(() => element.Opacity = 1); + if (initiallyVisible) await element.Dispatcher.RunAsync(() => element.Opacity = 1); return new AttachedAnimatableCompositionEffect(target, sprite, new CompositionAnimationParameters(animationPropertyName, on, off), disposeOnUnload); } @@ -596,7 +596,7 @@ public static async Task> Attach where T : FrameworkElement { // Get the compositor - Visual visual = await element.Dispatcher.GetFromUIThreadAsync(element.GetVisual); + Visual visual = await element.Dispatcher.GetAsync(element.GetVisual); Compositor compositor = visual.Compositor; // Create the blur effect and the effect factory @@ -648,7 +648,7 @@ public static async Task> Attach SpriteVisual sprite = compositor.CreateSpriteVisual(); sprite.Brush = effectBrush; await AddToTreeAndBindSizeAsync(target.GetVisual(), target, sprite); - if (initiallyVisible) await element.Dispatcher.RunOnUIThreadAsync(() => element.Opacity = 1); + if (initiallyVisible) await element.Dispatcher.RunAsync(() => element.Opacity = 1); return new AttachedCompositeAnimatableCompositionEffect(target, sprite, new Dictionary { @@ -675,7 +675,7 @@ public static async Task> Attach where T : FrameworkElement { // Get the compositor - Visual visual = await element.Dispatcher.GetFromUIThreadAsync(element.GetVisual); + Visual visual = await element.Dispatcher.GetAsync(element.GetVisual); Compositor compositor = visual.Compositor; // Create the blur effect, the saturation effect and the effect factory @@ -708,7 +708,7 @@ public static async Task> Attach SpriteVisual sprite = compositor.CreateSpriteVisual(); sprite.Brush = effectBrush; await AddToTreeAndBindSizeAsync(visual, element, sprite); - if (initiallyVisible) await element.Dispatcher.RunOnUIThreadAsync(() => element.Opacity = 1); + if (initiallyVisible) await element.Dispatcher.RunAsync(() => element.Opacity = 1); // Prepare and return the wrapped effect return new AttachedCompositeAnimatableCompositionEffect(element, sprite, @@ -732,7 +732,7 @@ public static async Task> Attach private static async Task AddToTreeAndBindSizeAsync([NotNull] Visual host, [NotNull] UIElement element, [NotNull] Visual visual) { // Add the shadow as a child of the host in the visual tree - await element.Dispatcher.RunOnUIThreadAsync(() => ElementCompositionPreview.SetElementChildVisual(element, visual)); + await element.Dispatcher.RunAsync(() => ElementCompositionPreview.SetElementChildVisual(element, visual)); // Make sure size of shadow host and shadow visual always stay in sync ExpressionAnimation bindSizeAnimation = host.Compositor.CreateExpressionAnimation($"{nameof(host)}.Size"); diff --git a/UICompositionAnimations/Helpers/DispatcherHelper.cs b/UICompositionAnimations/Helpers/DispatcherHelper.cs index ebe42aa..d3fbe94 100644 --- a/UICompositionAnimations/Helpers/DispatcherHelper.cs +++ b/UICompositionAnimations/Helpers/DispatcherHelper.cs @@ -19,7 +19,7 @@ public static class DispatcherHelper /// The target dispatcher to use to schedule the callback execution /// The action to execute on the UI thread [PublicAPI] - public static void RunOnUIThread([NotNull] this CoreDispatcher dispatcher, [NotNull] Action callback) + public static void Run([NotNull] this CoreDispatcher dispatcher, [NotNull] Action callback) { if (dispatcher.HasThreadAccess) callback(); else @@ -37,7 +37,7 @@ public static void RunOnUIThread([NotNull] this CoreDispatcher dispatcher, [NotN /// The target dispatcher to use to schedule the callback execution /// The action to execute on the UI thread [PublicAPI] - public static void RunOnUIThread([NotNull] this CoreDispatcher dispatcher, [NotNull] Func asyncCallback) + public static void Run([NotNull] this CoreDispatcher dispatcher, [NotNull] Func asyncCallback) { // Check the current thread if (dispatcher.HasThreadAccess) asyncCallback(); @@ -55,7 +55,7 @@ public static void RunOnUIThread([NotNull] this CoreDispatcher dispatcher, [NotN /// The target dispatcher to use to schedule the callback execution /// The action to execute on the UI thread [PublicAPI] - public static async Task RunOnUIThreadAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Action callback) + public static async Task RunAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Action callback) { if (dispatcher.HasThreadAccess) callback(); else @@ -76,7 +76,7 @@ public static async Task RunOnUIThreadAsync([NotNull] this CoreDispatcher dispat /// The target dispatcher to use to schedule the callback execution /// The action to execute on the UI thread [PublicAPI] - public static Task RunOnUIThreadAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Func asyncCallback) + public static Task RunAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Func asyncCallback) { // Check the current thread if (dispatcher.HasThreadAccess) return asyncCallback(); @@ -97,7 +97,7 @@ public static Task RunOnUIThreadAsync([NotNull] this CoreDispatcher dispatcher, /// The target dispatcher to use to schedule the callback execution /// The function to execute on the UI thread [PublicAPI] - public static async ValueTask GetFromUIThreadAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Func function) + public static async ValueTask GetAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Func function) { if (dispatcher.HasThreadAccess) return function(); TaskCompletionSource tcs = new TaskCompletionSource(); @@ -116,7 +116,7 @@ public static async ValueTask GetFromUIThreadAsync([NotNull] this CoreDisp /// The target dispatcher to use to schedule the callback execution /// The async function to execute on the UI thread [PublicAPI] - public static Task GetFromUIThreadAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Func> function) + public static Task GetAsync([NotNull] this CoreDispatcher dispatcher, [NotNull] Func> function) { // Check the current thread if (dispatcher.HasThreadAccess) return function(); @@ -152,28 +152,28 @@ public static Task GetFromUIThreadAsync([NotNull] this CoreDispatcher disp /// /// The action to execute on the UI thread [PublicAPI] - public static void RunOnUIThread([NotNull] Action callback) => CoreDispatcher.RunOnUIThread(callback); + public static void RunOnUIThread([NotNull] Action callback) => CoreDispatcher.Run(callback); /// /// Executes a given async action on the UI thread without awaiting the operation /// /// The action to execute on the UI thread [PublicAPI] - public static void RunOnUIThread([NotNull] Func asyncCallback) => CoreDispatcher.RunOnUIThread(asyncCallback); + public static void RunOnUIThread([NotNull] Func asyncCallback) => CoreDispatcher.Run(asyncCallback); /// /// Executes a given action on the UI thread and waits for it to be completed /// /// The action to execute on the UI thread [PublicAPI] - public static Task RunOnUIThreadAsync([NotNull] Action callback) => CoreDispatcher.RunOnUIThreadAsync(callback); + public static Task RunOnUIThreadAsync([NotNull] Action callback) => CoreDispatcher.RunAsync(callback); /// /// Executes a given action on the UI thread and waits for it to be completed /// /// The action to execute on the UI thread [PublicAPI] - public static Task RunOnUIThreadAsync([NotNull] Func asyncCallback) => CoreDispatcher.RunOnUIThreadAsync(asyncCallback); + public static Task RunOnUIThreadAsync([NotNull] Func asyncCallback) => CoreDispatcher.RunAsync(asyncCallback); /// /// Executes a given function on the UI thread and returns its result @@ -181,7 +181,7 @@ public static Task GetFromUIThreadAsync([NotNull] this CoreDispatcher disp /// The return type /// The function to execute on the UI thread [PublicAPI] - public static ValueTask GetFromUIThreadAsync([NotNull] Func function) => CoreDispatcher.GetFromUIThreadAsync(function); + public static ValueTask GetFromUIThreadAsync([NotNull] Func function) => CoreDispatcher.GetAsync(function); /// /// Executes a given async function on the UI thread and returns its result @@ -189,7 +189,7 @@ public static Task GetFromUIThreadAsync([NotNull] this CoreDispatcher disp /// The return type /// The async function to execute on the UI thread [PublicAPI] - public static Task GetFromUIThreadAsync([NotNull] Func> function) => CoreDispatcher.GetFromUIThreadAsync(function); + public static Task GetFromUIThreadAsync([NotNull] Func> function) => CoreDispatcher.GetAsync(function); #endregion }