Browse Source

Fixed some timers

pull/10691/head
Nikita Tsukanov 3 years ago
parent
commit
718089bda9
  1. 8
      src/Avalonia.Base/Threading/IDispatcherImpl.cs
  2. 2
      src/Avalonia.Controls/Platform/ManagedDispatcherImpl.cs

8
src/Avalonia.Base/Threading/IDispatcherImpl.cs

@ -30,7 +30,7 @@ public interface IControlledDispatcherImpl : IDispatcherImplWithPendingInput
void RunLoop(CancellationToken token);
}
internal class LegacyDispatcherImpl : IControlledDispatcherImpl
internal class LegacyDispatcherImpl : DefaultDispatcherClock, IControlledDispatcherImpl
{
private readonly IPlatformThreadingInterface _platformThreading;
private IDisposable? _timer;
@ -50,10 +50,14 @@ internal class LegacyDispatcherImpl : IControlledDispatcherImpl
{
_timer?.Dispose();
_timer = null;
if (dueTimeInMs.HasValue)
{
var interval = Math.Max(1, dueTimeInMs.Value - TickCount);
_timer = _platformThreading.StartTimer(DispatcherPriority.Send,
TimeSpan.FromMilliseconds(dueTimeInMs.Value),
TimeSpan.FromMilliseconds(interval),
OnTick);
}
}
private void OnTick()

2
src/Avalonia.Controls/Platform/ManagedDispatcherImpl.cs

@ -46,7 +46,7 @@ public class ManagedDispatcherImpl : IControlledDispatcherImpl
{
_nextTimer = dueTimeInMs == null
? null
: _clock.Elapsed + TimeSpan.FromMilliseconds(dueTimeInMs.Value);
: TimeSpan.FromMilliseconds(dueTimeInMs.Value);
if (!CurrentThreadIsLoopThread)
_wakeup.Set();
}

Loading…
Cancel
Save