From bca3b42a0caf6bf2be80d897bf18344c5f7f13d7 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Sun, 11 Aug 2019 09:09:56 +0300 Subject: [PATCH] Removed custom win32 render timer since it leaks pool threads --- src/Windows/Avalonia.Win32/RenderTimer.cs | 56 --------------------- src/Windows/Avalonia.Win32/Win32Platform.cs | 2 +- 2 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 src/Windows/Avalonia.Win32/RenderTimer.cs diff --git a/src/Windows/Avalonia.Win32/RenderTimer.cs b/src/Windows/Avalonia.Win32/RenderTimer.cs deleted file mode 100644 index 7dbb745a23..0000000000 --- a/src/Windows/Avalonia.Win32/RenderTimer.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Reactive.Disposables; -using System.Threading; -using Avalonia.Rendering; -using Avalonia.Win32.Interop; - -namespace Avalonia.Win32 -{ - internal class RenderTimer : DefaultRenderTimer - { - private UnmanagedMethods.WaitOrTimerCallback timerDelegate; - - private static IntPtr _timerQueue; - - private static void EnsureTimerQueueCreated() - { - if (Volatile.Read(ref _timerQueue) == null) - { - var queue = UnmanagedMethods.CreateTimerQueue(); - if (Interlocked.CompareExchange(ref _timerQueue, queue, IntPtr.Zero) != IntPtr.Zero) - { - UnmanagedMethods.DeleteTimerQueueEx(queue, IntPtr.Zero); - } - } - } - - public RenderTimer(int framesPerSecond) - : base(framesPerSecond) - { - } - - protected override IDisposable StartCore(Action tick) - { - EnsureTimerQueueCreated(); - var msPerFrame = 1000 / FramesPerSecond; - - timerDelegate = (_, __) => tick(TimeSpan.FromMilliseconds(Environment.TickCount)); - - UnmanagedMethods.CreateTimerQueueTimer( - out var timer, - _timerQueue, - timerDelegate, - IntPtr.Zero, - (uint)msPerFrame, - (uint)msPerFrame, - 0 - ); - - return Disposable.Create(() => - { - timerDelegate = null; - UnmanagedMethods.DeleteTimerQueueTimer(_timerQueue, timer, IntPtr.Zero); - }); - } - } -} diff --git a/src/Windows/Avalonia.Win32/Win32Platform.cs b/src/Windows/Avalonia.Win32/Win32Platform.cs index f20cf394bb..bc40ec2ff7 100644 --- a/src/Windows/Avalonia.Win32/Win32Platform.cs +++ b/src/Windows/Avalonia.Win32/Win32Platform.cs @@ -86,7 +86,7 @@ namespace Avalonia.Win32 .Bind().ToConstant(s_instance) .Bind().ToConstant(s_instance) .Bind().ToConstant(new RenderLoop()) - .Bind().ToConstant(new RenderTimer(60)) + .Bind().ToConstant(new DefaultRenderTimer(60)) .Bind().ToSingleton() .Bind().ToConstant(s_instance) .Bind().ToSingleton()