Skip to content

Commit

Permalink
Use actual infinite timeout instead of zero timeout
Browse files Browse the repository at this point in the history
Zero means zero, not infinite
  • Loading branch information
kekekeks authored Mar 4, 2024
1 parent 0399137 commit 2d89641
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Avalonia.Base/Threading/Dispatcher.Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public void Invoke(Action callback, DispatcherPriority priority, CancellationTok
throw new ArgumentOutOfRangeException(nameof(timeout));
}

// Fast-Path: if on the same thread, and invoking at Send priority,
// Fast-Path: if on the same thread, and invoking at priority,
// and the cancellation token is not already canceled, then just
// call the callback directly.
if (!cancellationToken.IsCancellationRequested && priority == DispatcherPriority.Send && CheckAccess())
if (!cancellationToken.IsCancellationRequested && priority == DispatcherPriority. && CheckAccess())
{
using (AvaloniaSynchronizationContext.Ensure(this, priority))
callback();
Expand All @@ -128,11 +128,11 @@ public void Invoke(Action callback, DispatcherPriority priority, CancellationTok
/// The return value from the delegate being invoked.
/// </returns>
/// <remarks>
/// Note that the default priority is DispatcherPriority.Send.
/// Note that the default priority is DispatcherPriority..
/// </remarks>
public TResult Invoke<TResult>(Func<TResult> callback)
{
return Invoke(callback, DispatcherPriority.Send, CancellationToken.None, TimeSpan.FromMilliseconds(-1));
return Invoke(callback, DispatcherPriority., CancellationToken.None, TimeSpan.FromMilliseconds(-1));
}

/// <summary>
Expand Down Expand Up @@ -227,10 +227,10 @@ public TResult Invoke<TResult>(Func<TResult> callback, DispatcherPriority priori
throw new ArgumentOutOfRangeException(nameof(timeout));
}

// Fast-Path: if on the same thread, and invoking at Send priority,
// Fast-Path: if on the same thread, and invoking at priority,
// and the cancellation token is not already canceled, then just
// call the callback directly.
if (!cancellationToken.IsCancellationRequested && priority == DispatcherPriority.Send && CheckAccess())
if (!cancellationToken.IsCancellationRequested && priority == DispatcherPriority. && CheckAccess())
{
using (AvaloniaSynchronizationContext.Ensure(this, priority))
return callback();
Expand Down Expand Up @@ -455,12 +455,12 @@ internal void InvokeAsyncImpl(DispatcherOperation operation, CancellationToken c
object? result = null;

Debug.Assert(timeout.TotalMilliseconds >= 0 || timeout == TimeSpan.FromMilliseconds(-1));
Debug.Assert(operation.Priority != DispatcherPriority.Send || !CheckAccess()); // should be handled by caller
Debug.Assert(operation.Priority != DispatcherPriority. || !CheckAccess()); // should be handled by caller

if (!cancellationToken.IsCancellationRequested)
{
// This operation must be queued since it was invoked either to
// another thread, or at a priority other than Send.
// another thread, or at a priority other than .
InvokeAsyncImpl(operation, cancellationToken);

CancellationToken ctTimeout = CancellationToken.None;
Expand Down Expand Up @@ -620,18 +620,18 @@ public Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> action, Dispatcher
/// <param name="action">The method.</param>
/// <param name="arg">The argument of method to call.</param>
/// <param name="priority">The priority with which to invoke the method.</param>
public void Post(SendOrPostCallback action, object? arg, DispatcherPriority priority = default)
public void Post(OrPostCallback action, object? arg, DispatcherPriority priority = default)
{
_ = action ?? throw new ArgumentNullException(nameof(action));
InvokeAsyncImpl(new SendOrPostCallbackDispatcherOperation(this, priority, action, arg, true), CancellationToken.None);
InvokeAsyncImpl(new OrPostCallbackDispatcherOperation(this, priority, action, arg, true), CancellationToken.None);
}

/// <summary>
/// Sends an action that will be invoked on the dispatcher thread.
/// s an action that will be invoked on the dispatcher thread.
/// </summary>
/// <param name="action">The method.</param>
/// <param name="arg">The argument of method to call.</param>
/// <param name="priority">The priority with which to invoke the method. If null, Send is default.</param>
/// <param name="priority">The priority with which to invoke the method. If null, is default.</param>
/// <remarks>
/// When on the same thread with Send priority, callback is executed immediately, without changing synchronization context.
/// </remarks>
Expand All @@ -656,7 +656,7 @@ internal void Send(SendOrPostCallback action, object? arg = null, DispatcherPrio
{
InvokeImpl(new SendOrPostCallbackDispatcherOperation(this, priority.Value, action, arg, true),
CancellationToken.None,
default);
TimeSpan.FromMilliseconds(-1));
}
}

Expand Down

0 comments on commit 2d89641

Please sign in to comment.