Hello,
I have an issue occurring in my application. I have a windows service
that is polling a table which is essentially a queue of events to
process. I have implemented the System.Threading.Timer in the OnStart
method to call a method that checks the queue for new events every 60
seconds. Within the callback method I set a variable value to the
current datetime the first time a set of events is grabbed. Then check
this vaiable at the start of the method each time it is called. The
code looks something like this:
public class demo
{
private DateTime _timeObject;
private System.Threading.Timer timerThread;
protected override void OnStart(string[] args)
{
timerThread= new System.Threading.Timer(CallbackMethod, null,
60000, 1000);
}
private void CallbackMethod(object state)
{
if(_timerObject == DateTime.MinValue)
{
--Get Events
_timerObject = DateTime.Now
--Do stuff
_timerObject = DateTime.MinValue
}
}
}
The idea behind this is that I want the CallbackMethod to finish
processing the first chunk of events before moving on to the next. For
some reason that I am unclear of, this is not what is happening. Each
time the Timer fires more events are grabbed.
Does anybody understand what I am missing? Any help would be greatly
appreciated.
Thanks in advance.
rbr