#JustLearned 6: Windows Service with Windows Timer control doesn’t tick

While designing a windows service if you are planning to use a timer control, make sure not use the System.Windows.Forms.Timer. The timer event will not tick. You have to use the System.Timers.Timer , which will work properly. I came to know about this after developing a windows service using the timer control. Also System.Threading might help, though I have not tried this.


private static System.Timers.Timer tmr;

public AlertService()
{
InitializeComponent();
tmr = new System.Timers.Timer(30* 60000);
}


protected override void OnStart(string[] args)
{
try
{
//Attach the elaspsed event of the timer
//Set the interval of timer to 30 minute and enable the timer.

tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed);
tmr.Interval = 30* 60000;
tmr.Enabled = true;
}
catch (Exception eg)
{
//your log
}
}