Browse Source

Prevent timer delegate being GCd.

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

Loading…
Cancel
Save