static void OnTimer()

in src/Connection.cs [944:992]


            static void OnTimer(object state)
            {
                var thisPtr = (HeartBeat)state;
                try
                {
                    if (thisPtr.connection.state == ConnectionState.CloseSent)
                    {
                        thisPtr.connection.state = ConnectionState.End;
                        thisPtr.connection.OnEnded(thisPtr.connection.Error);
                        return;
                    }

                    DateTime now = DateTime.UtcNow;
                    if (thisPtr.local > 0 &&
                        GetDueMilliseconds(thisPtr.local, now, thisPtr.lastReceive) == 0)
                    {
                        thisPtr.connection.CloseInternal(
                            0,
                            new Error(ErrorCode.ConnectionForced)
                            {
                                Description = Fx.Format("Connection closed after idle timeout {0} ms", thisPtr.local)
                            });
                        thisPtr.SetTimerForClose();
                        return;
                    }

                    if (thisPtr.remote > 0 &&
                        GetDueMilliseconds(thisPtr.remote, now, thisPtr.lastSend) == 0)
                    {
                        thisPtr.connection.writer.Send(new ByteBuffer(new byte[] { 0, 0, 0, 8, 2, 0, 0, 0 }, 0, 8, 8));
                        thisPtr.OnSend();
                        Trace.WriteLine(TraceLevel.Frame, "SEND (ch=0) empty");
                    }

                    if (!thisPtr.connection.IsClosed)
                    {
                        thisPtr.SetTimer();
                    }
                }
                catch (Exception exception)
                {
                    Trace.WriteLine(TraceLevel.Warning, "OnTimer: {0}:{1}", exception.GetType().Name, exception.Message);

                    if (!thisPtr.connection.IsClosed)
                    {
                        thisPtr.connection.OnException(exception);
                    }
                }
            }