Hi ,
This is my Scheduler.cs Code
private Timer timer1 = null;
public Scheduler()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
timer1 = new Timer();
this.timer1.Interval = 30000;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
this.timer1.Enabled = true;
Library.WriteErrorLog("Service Has Been Started");
}
private void timer1_Tick(object sender, ElapsedEventArgs e)
{
Library.WriteErrorLog("Timer ticked and some job doing");
sendEmailNotification();
Library.WriteErrorLog("Timer ticked and some job Completed");
}
private bool sendEmailNotification()
{
bool isSend = false;
try
{
MailMessage message = new MailMessage();
message.To.Add("xxx@gmail.com");
// if (!string.IsNullOrEmpty(dEmail.CC))
message.CC.Add("xxxx@gmail.com");
//if (!string.IsNullOrEmpty(dEmail.BCC))
// message.Bcc.Add(dEmail.BCC);
message.Subject = "Tezting";
message.Body = "Testing";
message.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Send(message);
isSend = true;
}
catch (Exception ex)
{
throw (ex);
}
return isSend;
}
protected override void OnStop()
{
timer1.Enabled = false;
Library.WriteErrorLog("Teh window service has been stopped");
}
Problem : In my log file its always printing like beloow:
4/6/2016 12:41:23 PMService Has Been Started
4/6/2016 12:41:53 PMTimer ticked and some job doing
4/6/2016 12:42:23 PMTimer ticked and some job doing
4/6/2016 12:42:53 PMTimer ticked and some job doing
4/6/2016 12:43:23 PMTimer ticked and some job doing
4/6/2016 12:43:53 PMTimer ticked and some job doing
4/6/2016 12:44:23 PMTimer ticked and some job doing
4/6/2016 12:44:53 PMTimer ticked and some job doing
4/6/2016 12:45:23 PMTimer ticked and some job doing
4/6/2016 12:45:53 PMTimer ticked and some job doing
its always printing job is doing...but not completed message