I am developing a Windows service that should perform several tasks at different periods.
Currently, I have two timers, a full timer and a stock timer, working at various intervals, as defined below.
fullTimer = new System.Timers.Timer();
fullTimer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
fullTimer.Interval = Convert.ToDouble(interval * 1000);
fullTimer.AutoReset = true;
fullTimer.Start(); // or fullTimer.Enabled = true;
GC.KeepAlive(fullTimer);
stockTimer = new System.Timers.Timer();
stockTimer.Elapsed += new ElapsedEventHandler(StockOnElapsedTime);
stockTimer.Interval = Convert.ToDouble(stockInterval * 1000);
stockTimer.AutoReset = true;
stockTimer.Start();
GC.KeepAlive(stockTimer);
Can anyone understand why the timers will not shoot. I get really weird behavior. If I start the stock handler manually
StockOnElapsedTime(null,null);
The timer seems to continue to fire correctly.
source
share