In my Window Service application the timer function is never called. I deployed the service on my machine and then attached the service to Visual Studio with breakpoints on different function. After OnStart() none of my functions are called.
Here's my OnStart() function
protected override void OnStart(string[] args)
{
this.timer = new System.Timers.Timer(50000);
this.timer.AutoReset = true;
this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
this.timer.Start();
}
Updated 09/12/2017 : Added Event log in try and catch
This function then calls timer1_tick():
private void timer1_Tick(object sender, EventArgs e)
{
try
{
EventLog.WriteEntry("Running.."+ e.ToString());
}
catch (Exception ex)
{
EventLog.WriteEntry("Caught Exception "+ex.ToString(), EventLogEntryType.Error);
}
}
The timer1_tick is never called. Any suggestions?
Update 12/09/2017 : I checked the Event log . Under Windows Logs > Application, I can see the message , service started successfully . However , the event logs added in the try-catch block aren't get displayed. Not sure if I am missing something.
I attached the service to Visual Studio for debugging. In the below image, the OnStart() method is called. I just added the Thread.Sleep(30000) so that I get some buffer time to attach the process to the debugger to avoid skipping the OnStart() function
After the Timer starts, I have a breakpoint on the TimerTick() function expecting it to be hit, but it never does


timer1_Tickis likely being called as everything in yourOnStartseems appropriate. Perhaps the reason you aren't receiving e-mails is because_SendEmailis throwing the exception.Writing to the
EventLogmight provide more information?As a best practice I would also write to the
EventLoginOnStartandOnStop.