I have a Web Service and i used timers inside it. when i run the service application inside my vs2010 it work's like a charm. but when i deploy it to the remote server it doesn't fire the ElapsedEventHandler. I used a Logger to log the events and i set the permissions for write into the log file. Let me explain more. I'm trying to write a service which waits for a job, and the job is sending email to a big list. and emails should be send by 20 secs interval. here is some part of my code:
public class EmailSender : IEmailSender
{
Queue<AdvEmail> ListOfEmails = new Queue<AdvEmail>();
List<EmailJob> EmailJobs = new List<EmailJob>();
Timer timerFetchJobs = null;
Timer timerSendEmails = null;
public EmailSender()
{
try
{
Logger.Log("init service");
timerFetchJobs = new Timer();
timerFetchJobs.Interval = 5 * 1000;
timerFetchJobs.Elapsed += new ElapsedEventHandler(timerFetchJobs_Elapsed);
timerFetchJobs.Enabled = true;
timerSendEmails = new Timer();
timerSendEmails.Interval = 20 * 1000;
timerSendEmails.Elapsed += new ElapsedEventHandler(timerSendEmails_Elapsed);
timerSendEmails.Enabled = true;
timerFetchJobs.Start();
timerSendEmails.Start();
Logger.Log("init service Ended Succefully");
Logger.Log("timerFetchJobs.Enabled=" + timerFetchJobs.Enabled.ToString());
Logger.Log("timerSendEmails.Enabled=" + timerSendEmails.Enabled.ToString());
}
catch (Exception ex)
{
Logger.Log("Error in InitService. Message: " + ex.Message);
}
}
void timerSendEmails_Elapsed(object sender, ElapsedEventArgs e)
{
timerSendEmails.Stop();
Logger.Log("Checking for Emails in the Queue");
timerSendEmails.Start();
}
void timerFetchJobs_Elapsed(object sender, ElapsedEventArgs e)
{
timerFetchJobs.Stop();
try
{
FetchJobsFromDB();
}
catch (Exception ex)
{
Logger.Log("Error in timerFetchJobs. Message: " + ex.Message);
}
timerFetchJobs.Start();
}
when i go to the service addreess from browser, it initializes and logs the init level correctly, but no clue of firing timers!! which i dont know why?? what I'm doing wrong? thanks
Edit: here is the log file when i run it locally:
Log Entry : 1392/01/30 08:47:09 : :init service-------------------------------
Log Entry : 1392/01/30 08:47:09 : :init service Ended Succefully-------------------------------
Log Entry : 1392/01/30 08:47:09 : :timerFetchJobs.Enabled=True-------------------------------
Log Entry : 1392/01/30 08:47:09 : :timerSendEmails.Enabled=True-------------------------------
Log Entry : 1392/01/30 08:47:14 : :Checking for Jobs in the Database-------------------------------
Log Entry : 1392/01/30 08:47:16 : :There is a new job. job name is Pad 71-------------------------------
Log Entry : 1392/01/30 08:47:19 : :Adding Emails for th job Pad 71-------------------------------
And here is the log file when i deploy it to remote server
Log Entry : 1392/01/30 08:47:09 : :init service-------------------------------
Log Entry : 1392/01/30 08:47:09 : :init service Ended Succefully-------------------------------
Log Entry : 1392/01/30 08:47:09 : :timerFetchJobs.Enabled=True-------------------------------
Log Entry : 1392/01/30 08:47:09 : :timerSendEmails.Enabled=True-------------------------------