private async Task ServiceStatusPingAsync(TimerAwaitable timer) { using (timer) { timer.Start(); while (await timer) { try { // Check if last send time is longer than default keep-alive ticks and then send ping if (Stopwatch.GetTimestamp() - Interlocked.Read(ref _lastSendTimestamp) > DefaultGetServiceStatusTicks) { await WriteAsync(RuntimeServicePingMessage.GetStatusPingMessage(true)); Interlocked.Exchange(ref _lastSendTimestamp, Stopwatch.GetTimestamp()); Log.SentServiceStatusPing(Logger); } } catch (Exception e) { Log.FailedSendingServiceStatusPing(Logger, e); } } } }
public bool Start() { if (Interlocked.Increment(ref _counter) == 1) { _timer.Start(); _ = PingAsync(_timer); return(true); } return(false); }
public ObjectWithTimerAwaitable(TaskCompletionSource tcs) { _tcs = tcs; _timer = new TimerAwaitable(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1)); _timer.Start(); }
private void Start() { _nextHeartbeat.Start(); _ = Task.Run(ExecuteTimerLoop); // Fire and forget the timer loop }