static void OnHeartBeatTimer(object state)
{
TimedHeartBeat thisPtr = (TimedHeartBeat)state;
if (thisPtr.connection.IsClosing())
{
return;
}
DateTime now = DateTime.UtcNow;
try
{
if (thisPtr.localInterval < uint.MaxValue &&
now.Subtract(thisPtr.lastReceiveTime).TotalMilliseconds > thisPtr.localInterval)
{
string message = AmqpResources.GetString(AmqpResources.AmqpConnectionInactive, thisPtr.localInterval);
AmqpTrace.Provider.AmqpLogError(thisPtr.connection, "OnHeartBeatTimer", message);
thisPtr.connection.SafeClose(new AmqpException(AmqpErrorCode.ConnectionForced, message));
return;
}
if (thisPtr.remoteInterval < uint.MaxValue &&
now.Subtract(thisPtr.lastSendTime).TotalMilliseconds >= thisPtr.remoteInterval)
{
thisPtr.connection.SendCommand(null, 0, null);
}
thisPtr.SetTimer(now);
}
catch (Exception exception)
{
if (Fx.IsFatal(exception))
{
throw;
}
if (!thisPtr.connection.IsClosing())
{
AmqpTrace.Provider.AmqpLogError(thisPtr.connection, "OnHeartBeatTimer", exception.Message);
thisPtr.connection.SafeClose(exception);
}
}
}
}