Click here to Skip to main content
15,885,546 members

system.timers.timer doesn't fire the elapsed event on the server

mahdi87_gh asked:

Open original thread
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:
C#
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");
        // some statments here

        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-------------------------------
Tags: C# (C# 4.0), Visual Studio (Visual Studio 2010), Webservice

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900