#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()
tmr = new System.Timers.Timer(30* 60000);

protected override void OnStart(string[] args)
//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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s