System.Timers.Timer() sometimes gets stuck and disappears??

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello,

Wow...I have one for you all and hopefully I am not understanding this timer
object correctly. I have a timer setup that pulses a connection through a
socket every 60 seconds. But it seems recently connections just drop off
because the timer stops firing.

My question is if there is a timeout in the timer event that just shuts down
the call if the timer event is taking too long to complete...?

It seems that it almost looks when reading log files that something either
locks up inthe timer event and never retruns (very unlikely since it happens
at different places in the event), or the event just stops running in the
middle of something although the user application never reports any error
boxes to the user and they continue to use it for hours.

Here is some code if it helps you all out:

// in constructor
this.HeartBeatTimer = new System.Timers.Timer();
this.HeartBeatTimer.Interval = 1 * 60 * 1000; // every
1 minute
this.HeartBeatTimer.Elapsed += new
System.Timers.ElapsedEventHandler(DoHeartBeat); // send heartbeat

// later in code they log in and...
this.HeartBeatTimer.Enabled = true;

{At this point everything works fine for a long time.}

// my event handler
public void DoHeartBeat(object sender, EventArgs eArgs)
{
LogStuff.LogData("$$ FIRED Heartbeat --> just set enabled to false"); // ttt

// Shut down the timer until we are done sending the heartbeat
HeartBeatTimer.Enabled = false;

if(blah...)
{
LogStuff.LogData("$$ A"); // ttt

try
{
// query an activeX control to check statuses
...
LogStuff.LogData("$$ B"); // ttt

// send Heart Beat
String recData = mySocketClient.Send(....);

LogStuff.LogData("$$ C"); // ttt

}
catch(...)
{
// logging my error here
}

} // end IF

LogStuff.LogData("$$ Done firing heartbeat --> Enabled HB again.");

// Start the timer back up again when we are done
HeartBeatTimer.Enabled = true;

return;

} // end DoHeartBeat ()

Thats it. Nowhere in there do I have a return except at the very end. It
should never exit before it gets to the return. It never throws an error
either since nothing is ever logged at that spot (except other circumstances
when other things go wrong).

Sometimes when I read the log file I will see:
$$ FIRED Heartbeat --> just set enabled to false
$$ A
.... and thats it, Nothing from this timer ever again until program restarts.

Sometimes I will see:
$$ FIRED Heartbeat --> just set enabled to false
$$ A
$$ B
.... and thats it, Nothing from this timer ever again until program restarts.

I cannot reproduce this locally. It seems this happens after hours of use
on our customers computers.

Please, can anyone help us understand these timers any better?

Thank you all very much for reading this. Hope someone can help.

Rob K

.



Relevant Pages

  • Re: Timer Count Down
    ... Try putting a break-point inside the Timer event. ... Doug Steele, Microsoft Access MVP ... ExpiryDtm field in table Countdown when the form opens. ...
    (microsoft.public.access.formscoding)
  • Re: Timer Count Down
    ... What I was trying to say is that you only need the timer when you actually ... Doug Steele, Microsoft Access MVP ... ExpiryDtm field in table Countdown when the form opens. ... Inside the form's Timer event, ...
    (microsoft.public.access.formscoding)
  • Re: SetTimer question
    ... that "method" doesn' t use the timer event of the hidden form at all. ... Also, as far as I know, you can't subclasify Access main window because it ...
    (microsoft.public.vb.winapi)
  • Re: Scrolling text in a stationary label help needed
    ... Actually it's not working properly John. ... I assume that you're setting the ScaleMode of both the Form and the Picture Box to vbPixels. ... The other thing, which is very important, is the fact that your code is still not actually running in the Timer, at least not in the way it is meant to. ... You do this *just once* inside the Timer event. ...
    (microsoft.public.vb.general.discussion)
  • Re: Scrolling text in a stationary label help needed
    ... I had to add a check in the timer event to ... Dim xposition As Long ... Private Sub Form_KeyPress ... In your example the code isn't runnng in a Timer at ...
    (microsoft.public.vb.general.discussion)