Browse Source

Prevent timer delegate being GCd.

pull/10/head
Steven Kirk 11 years ago
parent
commit
30900b6e00
  1. 7
      Windows/Perspex.Win32/Win32Platform.cs

7
Windows/Perspex.Win32/Win32Platform.cs

@ -7,6 +7,7 @@
namespace Perspex.Win32
{
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
@ -21,6 +22,8 @@ namespace Perspex.Win32
{
private static Win32Platform instance = new Win32Platform();
private List<Delegate> delegates = new List<Delegate>();
public static void Initialize()
{
var locator = Locator.CurrentMutable;
@ -48,8 +51,12 @@ namespace Perspex.Win32
(uint)interval.TotalMilliseconds,
timerDelegate);
// Prevent timerDelegate being garbage collected.
this.delegates.Add(timerDelegate);
return Disposable.Create(() =>
{
this.delegates.Remove(timerDelegate);
UnmanagedMethods.KillTimer(IntPtr.Zero, handle);
});
}

Loading…
Cancel
Save