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, thoguh 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 } }
Published under: Microsoft .NET Tips · · · ·
Good one manas... But never experienced this problem myself as i always took code from google or my previous projects... :)
Possible reason - Windows.Forms.Timer depends on UI Pumps and that is not available here. Ideally it should work and I'll get it checked.
Please share with us if you are able to use that, this will help. UI Pump is the reason even i am aware of that.