G
Guest
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
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