Browse Source

Rename Dispatcher invoke methods.

`InvokeAsync` -> `Post`
`InvokeTaskAsync` -> `InvokeAsync`
Steven Kirk 7 years ago
parent
commit
64ed0761c7

+ 2 - 2
samples/Previewer/MainWindow.xaml.cs

@@ -39,7 +39,7 @@ namespace Previewer
             }));
             new BsonTcpTransport().Listen(IPAddress.Loopback, 25000, t =>
             {
-                Dispatcher.UIThread.InvokeAsync(() =>
+                Dispatcher.UIThread.Post(() =>
                 {
                     if (_connection != null)
                     {
@@ -61,7 +61,7 @@ namespace Previewer
 
         private void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj)
         {
-            Dispatcher.UIThread.InvokeAsync(() =>
+            Dispatcher.UIThread.Post(() =>
             {
                 if (transport != _connection)
                     return;

+ 2 - 2
samples/RemoteTest/Program.cs

@@ -25,7 +25,7 @@ namespace RemoteTest
             var transport = new BsonTcpTransport();
             transport.Listen(IPAddress.Loopback, port, sc =>
             {
-                Dispatcher.UIThread.InvokeAsync(() =>
+                Dispatcher.UIThread.Post(() =>
                 {
                     new RemoteServer(sc).Content = new MainView();
                 });
@@ -34,7 +34,7 @@ namespace RemoteTest
             var cts = new CancellationTokenSource();
             transport.Connect(IPAddress.Loopback, port).ContinueWith(t =>
             {
-                Dispatcher.UIThread.InvokeAsync(() =>
+                Dispatcher.UIThread.Post(() =>
                 {
                     var window = new Window()
                     {

+ 1 - 1
src/Avalonia.Base/AvaloniaObject.cs

@@ -774,7 +774,7 @@ namespace Avalonia
             }
             else
             {
-                Dispatcher.UIThread.InvokeAsync(Set);
+                Dispatcher.UIThread.Post(Set);
             }
         }
 

+ 2 - 2
src/Avalonia.Base/PriorityBindingEntry.cs

@@ -123,7 +123,7 @@ namespace Avalonia
             }
             else
             {
-                Dispatcher.UIThread.InvokeAsync(Signal);
+                Dispatcher.UIThread.Post(Signal);
             }
         }
 
@@ -135,7 +135,7 @@ namespace Avalonia
             }
             else
             {
-                Dispatcher.UIThread.InvokeAsync(() => _owner.Completed(this));
+                Dispatcher.UIThread.Post(() => _owner.Completed(this));
             }
         }
     }

+ 1 - 1
src/Avalonia.Base/Threading/AvaloniaScheduler.cs

@@ -33,7 +33,7 @@ namespace Avalonia.Threading
                 if (!Dispatcher.UIThread.CheckAccess())
                 {
                     var cancellation = new CancellationDisposable();
-                    Dispatcher.UIThread.InvokeAsync(() =>
+                    Dispatcher.UIThread.Post(() =>
                     {
                         if (!cancellation.Token.IsCancellationRequested)
                         {

+ 2 - 2
src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs

@@ -36,7 +36,7 @@ namespace Avalonia.Threading
         /// <inheritdoc/>
         public override void Post(SendOrPostCallback d, object state)
         {
-           Dispatcher.UIThread.InvokeAsync(() => d(state), DispatcherPriority.Send);
+           Dispatcher.UIThread.Post(() => d(state), DispatcherPriority.Send);
         }
 
         /// <inheritdoc/>
@@ -45,7 +45,7 @@ namespace Avalonia.Threading
             if (Dispatcher.UIThread.CheckAccess())
                 d(state);
             else
-                Dispatcher.UIThread.InvokeTaskAsync(() => d(state), DispatcherPriority.Send).Wait();
+                Dispatcher.UIThread.InvokeAsync(() => d(state), DispatcherPriority.Send).Wait();
         }
     }
 }

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

@@ -79,13 +79,13 @@ namespace Avalonia.Threading
         public void RunJobs(DispatcherPriority minimumPriority) => _jobRunner.RunJobs(minimumPriority);
 
         /// <inheritdoc/>
-        public Task InvokeTaskAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
+        public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
         {
             return _jobRunner?.InvokeAsync(action, priority);
         }
 
         /// <inheritdoc/>
-        public void InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
+        public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
         {
             _jobRunner?.Post(action, priority);
         }

+ 2 - 2
src/Avalonia.Base/Threading/IDispatcher.cs

@@ -25,7 +25,7 @@ namespace Avalonia.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>
-        void InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal);
+        void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal);
 
         /// <summary>
         /// Post action that will be invoked on main thread
@@ -34,6 +34,6 @@ namespace Avalonia.Threading
         /// <param name="priority">The priority with which to invoke the method.</param>
         // TODO: The naming of this method is confusing: the Async suffix usually means return a task.
         // Remove this and rename InvokeTaskAsync as InvokeAsync. See #816.
-        Task InvokeTaskAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal);
+        Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal);
     }
 }

+ 1 - 1
src/Avalonia.Controls/Presenters/TextPresenter.cs

@@ -191,7 +191,7 @@ namespace Avalonia.Controls.Presenters
                     // The measure is currently invalid so there's no point trying to bring the 
                     // current char into view until a measure has been carried out as the scroll
                     // viewer extents may not be up-to-date.
-                    Dispatcher.UIThread.InvokeAsync(
+                    Dispatcher.UIThread.Post(
                         () =>
                         {
                             var rect = FormattedText.HitTestTextPosition(caretIndex);

+ 1 - 1
src/Avalonia.Controls/Remote/RemoteWidget.cs

@@ -18,7 +18,7 @@ namespace Avalonia.Controls.Remote
         public RemoteWidget(IAvaloniaRemoteTransportConnection connection)
         {
             _connection = connection;
-            _connection.OnMessage += (t, msg) => Dispatcher.UIThread.InvokeAsync(() => OnMessage(msg));
+            _connection.OnMessage += (t, msg) => Dispatcher.UIThread.Post(() => OnMessage(msg));
             _connection.Send(new ClientSupportedPixelFormatsMessage
             {
                 Formats = new[]

+ 5 - 5
src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs

@@ -46,16 +46,16 @@ namespace Avalonia.Controls.Remote.Server
                     {
                         _lastReceivedFrame = lastFrame.SequenceId;
                     }
-                    Dispatcher.UIThread.InvokeAsync(RenderIfNeeded);
+                    Dispatcher.UIThread.Post(RenderIfNeeded);
                 }
                 if (obj is ClientSupportedPixelFormatsMessage supportedFormats)
                 {
                     lock (_lock)
                         _supportedFormats = supportedFormats.Formats;
-                    Dispatcher.UIThread.InvokeAsync(RenderIfNeeded);
+                    Dispatcher.UIThread.Post(RenderIfNeeded);
                 }
                 if (obj is MeasureViewportMessage measure)
-                    Dispatcher.UIThread.InvokeAsync(() =>
+                    Dispatcher.UIThread.Post(() =>
                     {
                         var m = Measure(new Size(measure.Width, measure.Height));
                         _transport.Send(new MeasureViewportMessage
@@ -69,7 +69,7 @@ namespace Avalonia.Controls.Remote.Server
                     lock (_lock)
                     {
                         if (_pendingAllocation == null)
-                            Dispatcher.UIThread.InvokeAsync(() =>
+                            Dispatcher.UIThread.Post(() =>
                             {
                                 ClientViewportAllocatedMessage allocation;
                                 lock (_lock)
@@ -168,7 +168,7 @@ namespace Avalonia.Controls.Remote.Server
         public override void Invalidate(Rect rect)
         {
             _invalidated = true;
-            Dispatcher.UIThread.InvokeAsync(RenderIfNeeded);
+            Dispatcher.UIThread.Post(RenderIfNeeded);
         }
 
         public override IMouseDevice MouseDevice { get; } = new MouseDevice();

+ 1 - 1
src/Avalonia.Controls/TreeView.cs

@@ -250,7 +250,7 @@ namespace Avalonia.Controls
 
                         if (AutoScrollToSelectedItem)
                         {
-                            Dispatcher.UIThread.InvokeAsync(container.ContainerControl.BringIntoView);
+                            Dispatcher.UIThread.Post(container.ContainerControl.BringIntoView);
                         }
 
                         break;

+ 1 - 1
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@@ -49,7 +49,7 @@ namespace Avalonia.DesignerSupport.Remote
             // In previewer mode we completely ignore client-side viewport size
             if (obj is ClientViewportAllocatedMessage alloc)
             {
-                Dispatcher.UIThread.InvokeAsync(() => SetDpi(new Vector(alloc.DpiX, alloc.DpiY)));
+                Dispatcher.UIThread.Post(() => SetDpi(new Vector(alloc.DpiX, alloc.DpiY)));
                 return;
             }
             base.OnMessage(transport, obj);

+ 1 - 1
src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

@@ -140,7 +140,7 @@ namespace Avalonia.DesignerSupport.Remote
             };
         }
         
-        private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transport, object obj) => Dispatcher.UIThread.InvokeAsync(() =>
+        private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transport, object obj) => Dispatcher.UIThread.Post(() =>
         {
             if (obj is ClientSupportedPixelFormatsMessage formats)
             {

+ 1 - 1
src/Avalonia.Layout/LayoutManager.cs

@@ -203,7 +203,7 @@ namespace Avalonia.Layout
         {
             if (!_queued && !_running)
             {
-                Dispatcher.UIThread.InvokeAsync(ExecuteLayoutPass, DispatcherPriority.Layout);
+                Dispatcher.UIThread.Post(ExecuteLayoutPass, DispatcherPriority.Layout);
                 _queued = true;
             }
         }

+ 1 - 1
src/Avalonia.Visuals/Rendering/DeferredRenderer.cs

@@ -415,7 +415,7 @@ namespace Avalonia.Rendering
                     if (!_updateQueued && (_dirty == null || _dirty.Count > 0))
                     {
                         _updateQueued = true;
-                        _dispatcher.InvokeAsync(UpdateScene, DispatcherPriority.Render);
+                        _dispatcher.Post(UpdateScene, DispatcherPriority.Render);
                     }
 
                     Scene scene = null;

+ 1 - 1
src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs

@@ -351,7 +351,7 @@ namespace Avalonia.Gtk3
 
         void OnInput(RawInputEventArgs args)
         {
-            Dispatcher.UIThread.InvokeAsync(() => Input?.Invoke(args), DispatcherPriority.Input);
+            Dispatcher.UIThread.Post(() => Input?.Invoke(args), DispatcherPriority.Input);
         }
 
         public Point PointToClient(Point point)

+ 1 - 1
src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs

@@ -41,7 +41,7 @@ namespace Avalonia.LinuxFramebuffer
             if(_renderQueued)
                 return;
             _renderQueued = true;
-            Dispatcher.UIThread.InvokeAsync(() =>
+            Dispatcher.UIThread.Post(() =>
             {
                 Paint?.Invoke(new Rect(default(Point), ClientSize));
                 _renderQueued = false;

+ 1 - 1
src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs

@@ -62,7 +62,7 @@ public static class LinuxFramebufferPlatformExtensions
 
         public TokenClosable(CancellationToken token)
         {
-            token.Register(() => Dispatcher.UIThread.InvokeAsync(() => Closed?.Invoke(this, new EventArgs())));
+            token.Register(() => Dispatcher.UIThread.Post(() => Closed?.Invoke(this, new EventArgs())));
         }
     }
 

+ 1 - 1
src/OSX/Avalonia.MonoMac/TopLevelImpl.cs

@@ -107,7 +107,7 @@ namespace Avalonia.MonoMac
                     if (_nonUiRedrawQueued)
                         return;
                     _nonUiRedrawQueued = true;
-                    Dispatcher.UIThread.InvokeAsync(
+                    Dispatcher.UIThread.Post(
                         () =>
                         {
                             lock (SyncRoot)

+ 2 - 2
tests/Avalonia.UnitTests/ImmediateDispatcher.cs

@@ -14,12 +14,12 @@ namespace Avalonia.UnitTests
             return true;
         }
 
-        public void InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
+        public void Post(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
         {
             action();
         }
 
-        public Task InvokeTaskAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
+        public Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
         {
             action();
             return Task.FromResult<object>(null);

+ 2 - 2
tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs

@@ -24,13 +24,13 @@ namespace Avalonia.Visuals.UnitTests.Rendering
             var root = new TestRoot();
 
             var dispatcher = new Mock<IDispatcher>();
-            dispatcher.Setup(x => x.InvokeAsync(It.IsAny<Action>(), DispatcherPriority.Render))
+            dispatcher.Setup(x => x.Post(It.IsAny<Action>(), DispatcherPriority.Render))
                 .Callback<Action, DispatcherPriority>((a, p) => a());
 
             CreateTargetAndRunFrame(root, dispatcher: dispatcher.Object);
 
             dispatcher.Verify(x => 
-                x.InvokeAsync(
+                x.Post(
                     It.Is<Action>(a => a.Method.Name == "UpdateScene"),
                     DispatcherPriority.Render));
         }