Why does my DispatcherTimer not fire it's "tick" event?

57 Views Asked by At

I (thought I) know how to use a DispatcherTimer in a WPF application:

namespace TimerTestbed
{
    public partial class MainWindow : Window
    {
        DispatcherTimer timer = new DispatcherTimer();

        public MainWindow()
        {
            InitializeComponent();

            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += delegate 
            {
                Debug.WriteLine("Tick!");
            };
            timer.Start();
        }
    }
}

This gives me nice regular "Tick!" in the Output window :-)

However, if I use that same code "out in the wild", in it's natural habitat so to speak, I do not get the tick event fired.

public class Patcher : MyObject
    {
        DispatcherTimer timer = new DispatcherTimer();

        public Patcher()
        {
            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += delegate
            {
                Debug.WriteLine("Tick!");
            };
            timer.Start();
        }
    }

I have confirmed, that the Patcher-object is still alive and I have a bunch of other objects that happily fire their events when their respective time has come.

Can anyone point me to how I diagnose this issue? Is there a limitation on the use of a DispatcherTimer that I am unaware of?

Thanks,...

0

There are 0 best solutions below