Question : System.Threading.Timer problem.

Dear experts,

I have a console application that uses System.Threading.Timer to perform certain database operation regularly. When all that needs to be done is to write some line on the console, the timer works fine. But when I add the database stuff, the method is called only once. Could you please explain to me why this happens?
I used various time intervals, with the same result.
Thanks.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
static void Main(string[] args)
        {
            Timer tpsTimer = new Timer(CheckForPastDue, null, 1200, 30000);
            while(true);
        }

        public static void CheckForPastDue(Object stateInfo)
        {
            try
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString());

                // Check for titles past due
                string commandText = @"SELECT nl.ID, nl.BookStem, nl.To, n.LastName, n.FirstName FROM narratorlinks nl 
                                   JOIN Narrators n ON nl.NarratorStem = n.NarratorStem
                                   WHERE `TO` - INTERVAL 3 DAY <= NOW() AND nl.AudioReceive IS NULL;";

                object result = DBOperations.Execute(false, CommandType.Text, null, commandText, null);
...

Answer : System.Threading.Timer problem.

is there a reason you are using a Threading.Timer vs the System.Timer?    A threading.timer The CheckForPastDue method is executing on another thread then the one that created it.  this sometimes causes issues for the simple thing that you are trying to accomplish.  I had a similar issue and using the System.Timer worked for me.
Random Solutions  
 
programming4us programming4us