Browse Source

Rename Dispatcher invoke methods.

`InvokeAsync` -> `Post`
`InvokeTaskAsync` -> `InvokeAsync`
pull/1340/head
Steven Kirk 9 years ago
parent
commit
64ed0761c7
  1. 4
      samples/Previewer/MainWindow.xaml.cs
  2. 4
      samples/RemoteTest/Program.cs
  3. 2
      src/Avalonia.Base/AvaloniaObject.cs
  4. 4
      src/Avalonia.Base/PriorityBindingEntry.cs
  5. 2
      src/Avalonia.Base/Threading/AvaloniaScheduler.cs
  6. 4
      src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs
  7. 4
      src/Avalonia.Base/Threading/Dispatcher.cs
  8. 4
      src/Avalonia.Base/Threading/IDispatcher.cs
  9. 2
      src/Avalonia.Controls/Presenters/TextPresenter.cs
  10. 2
      src/Avalonia.Controls/Remote/RemoteWidget.cs
  11. 10
      src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs
  12. 2
      src/Avalonia.Controls/TreeView.cs
  13. 2
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  14. 2
      src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
  15. 2
      src/Avalonia.Layout/LayoutManager.cs
  16. 2
      src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
  17. 2
      src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs
  18. 2
      src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs
  19. 2
      src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs
  20. 2
      src/OSX/Avalonia.MonoMac/TopLevelImpl.cs
  21. 4
      tests/Avalonia.UnitTests/ImmediateDispatcher.cs
  22. 4
      tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs

4
samples/Previewer/MainWindow.xaml.cs

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

4
samples/RemoteTest/Program.cs

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

2
src/Avalonia.Base/AvaloniaObject.cs

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

4
src/Avalonia.Base/PriorityBindingEntry.cs

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

2
src/Avalonia.Base/Threading/AvaloniaScheduler.cs

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

4
src/Avalonia.Base/Threading/AvaloniaSynchronizationContext.cs

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

4
src/Avalonia.Base/Threading/Dispatcher.cs

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

4
src/Avalonia.Base/Threading/IDispatcher.cs

@ -25,7 +25,7 @@ namespace Avalonia.Threading
/// <param name="action">The method.</param> /// <param name="action">The method.</param>
/// <param name="priority">The priority with which to invoke 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> /// <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> /// <summary>
/// Post action that will be invoked on main thread /// 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> /// <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. // 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. // 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);
} }
} }

2
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 // 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 // current char into view until a measure has been carried out as the scroll
// viewer extents may not be up-to-date. // viewer extents may not be up-to-date.
Dispatcher.UIThread.InvokeAsync( Dispatcher.UIThread.Post(
() => () =>
{ {
var rect = FormattedText.HitTestTextPosition(caretIndex); var rect = FormattedText.HitTestTextPosition(caretIndex);

2
src/Avalonia.Controls/Remote/RemoteWidget.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls.Remote
public RemoteWidget(IAvaloniaRemoteTransportConnection connection) public RemoteWidget(IAvaloniaRemoteTransportConnection connection)
{ {
_connection = 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 _connection.Send(new ClientSupportedPixelFormatsMessage
{ {
Formats = new[] Formats = new[]

10
src/Avalonia.Controls/Remote/Server/RemoteServerTopLevelImpl.cs

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

2
src/Avalonia.Controls/TreeView.cs

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

2
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@ -49,7 +49,7 @@ namespace Avalonia.DesignerSupport.Remote
// In previewer mode we completely ignore client-side viewport size // In previewer mode we completely ignore client-side viewport size
if (obj is ClientViewportAllocatedMessage alloc) 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; return;
} }
base.OnMessage(transport, obj); base.OnMessage(transport, obj);

2
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) if (obj is ClientSupportedPixelFormatsMessage formats)
{ {

2
src/Avalonia.Layout/LayoutManager.cs

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

2
src/Avalonia.Visuals/Rendering/DeferredRenderer.cs

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

2
src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs

@ -351,7 +351,7 @@ namespace Avalonia.Gtk3
void OnInput(RawInputEventArgs args) 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) public Point PointToClient(Point point)

2
src/Linux/Avalonia.LinuxFramebuffer/FramebufferToplevelImpl.cs

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

2
src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs

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

2
src/OSX/Avalonia.MonoMac/TopLevelImpl.cs

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

4
tests/Avalonia.UnitTests/ImmediateDispatcher.cs

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

4
tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs

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

Loading…
Cancel
Save