System.Threading.Timer

4 views
Skip to first unread message

rbr

unread,
Apr 6, 2009, 5:02:34 PM4/6/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
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

rbr

unread,
Apr 7, 2009, 11:51:03 AM4/7/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Never mind. It was an environment issue!

Thanks.

rbr

Del N. Quent

unread,
Apr 7, 2009, 9:42:34 AM4/7/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
> private void CallbackMethod(object state)
> {
timerThread.Change(Timeout.Infinite, Timeout.Infinite); //
suspend indefinitely ... ADD
// if(_timerObject == DateTime.MinValue) ... REMOVE
> {
> --Get Events
// _timerObject = DateTime.Now ... REMOVE
> --Do stuff
// _timerObject = DateTime.MinValue ... REMOVE
// } ... REMOVE
timerThread.Change(60000, 60000); // reactivate ... ADD
> }

On Apr 6, 4:02 pm, rbr <ryankbr...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages