private TimerAwaitable StartKeepAliveTimer() { Log.StartingKeepAliveTimer(Logger, DefaultKeepAliveInterval); _lastReceiveTimestamp = Stopwatch.GetTimestamp(); _lastSendTimestamp = _lastReceiveTimestamp; var timer = new TimerAwaitable(DefaultKeepAliveInterval, DefaultKeepAliveInterval); _ = KeepAliveAsync(timer); return(timer); }
private async Task KeepAliveAsync(TimerAwaitable timer) { using (timer) { timer.Start(); while (await timer) { if (Stopwatch.GetTimestamp() - Interlocked.Read(ref _lastReceiveTimestamp) > DefaultServiceTimeoutTicks) { AbortConnection(); // We shouldn't get here twice. continue; } } } }