I have a DispatcherTimer i have initialised like so:
static DispatcherTimer _timer = new DispatcherTimer();
static void Main()
{
_timer.Interval = new TimeSpan(0, 0, 5);
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Start();
}
static void _timer_Tick(object sender, EventArgs e)
{
//do something
}
The _timer_Tick event never gets fired, have i missed something?
If this is your main entry point, it’s likely (near certain) that the
Mainmethod exits prior to when the firstDispatcherTimerevent could ever occur.As soon as Main finishes, the process will shut down, as there are no other foreground threads.
That being said,
DispatcherTimerreally only makes sense in a use case where you have aDispatcher, such as a WPF or Silverlight application. For a console mode application, you should consider using the Timer class, ie: