Parcourir la source

Replaced InvokeAsync with Invoke and InvokeTask to avoid exception swallowing and misunderstanding

Nikita Tsukanov il y a 10 ans
Parent
commit
21f977ac9d

+ 2 - 2
src/Perspex.Base/Threading/Dispatcher.cs

@@ -58,7 +58,7 @@ namespace Perspex.Threading
         /// <param name="action">The method.</param>
         /// <param name="priority">The priority with which to invoke the method.</param>
         /// <returns>A task that can be used to track the method's execution.</returns>
-        public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
+        public Task InvokeTask(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
         {
             return _jobRunner.InvokeAsync(action, priority);
         }
@@ -68,7 +68,7 @@ namespace Perspex.Threading
         /// </summary>
         /// <param name="action">The method.</param>
         /// <param name="priority">The priority with which to invoke the method.</param>
-        internal void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
+        public void Invoke(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
         {
             _jobRunner.Post(action, priority);
         }

+ 1 - 1
src/Perspex.Base/Threading/DispatcherTimer.cs

@@ -177,7 +177,7 @@ namespace Perspex.Threading
         /// </summary>
         private void InternalTick()
         {
-            Dispatcher.UIThread.Post(RaiseTick, _priority);
+            Dispatcher.UIThread.Invoke(RaiseTick, _priority);
         }
 
         /// <summary>

+ 2 - 2
src/Perspex.Base/Threading/PerspexSynchronizationContext.cs

@@ -36,14 +36,14 @@ namespace Perspex.Threading
         /// <inheritdoc/>
         public override void Post(SendOrPostCallback d, object state)
         {
-           Dispatcher.UIThread.Post(() => d(state));
+           Dispatcher.UIThread.Invoke(() => d(state));
         }
 
         /// <inheritdoc/>
         public override void Send(SendOrPostCallback d, object state)
         {
             // TODO: Add check for being on the main thread, we should invoke the method immediately in this case
-            Dispatcher.UIThread.InvokeAsync(() => d(state)).Wait();
+            Dispatcher.UIThread.InvokeTask(() => d(state)).Wait();
         }
     }
 }

+ 1 - 1
src/Perspex.Controls/Platform/ITopLevelRenderer.cs

@@ -44,7 +44,7 @@ namespace Perspex.Controls.Platform
             }));
             resources.Add(queueManager.RenderNeeded.Subscribe(_
                 =>
-                Dispatcher.UIThread.InvokeAsync(() => topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize)))));
+                Dispatcher.UIThread.Invoke(() => topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize)))));
 
             topLevel.PlatformImpl.Paint = rect =>
             {

+ 1 - 1
src/Perspex.Controls/TopLevel.cs

@@ -365,7 +365,7 @@ namespace Perspex.Controls
         /// </summary>
         private void HandleLayoutNeeded()
         {
-            Dispatcher.UIThread.InvokeAsync(LayoutManager.ExecuteLayoutPass, DispatcherPriority.Render);
+            Dispatcher.UIThread.Invoke(LayoutManager.ExecuteLayoutPass, DispatcherPriority.Render);
         }
 
         /// <summary>