Example #1
0
        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);
                    }
                }
            }
        }
Example #2
0
 public bool Start()
 {
     if (Interlocked.Increment(ref _counter) == 1)
     {
         _timer.Start();
         _ = PingAsync(_timer);
         return(true);
     }
     return(false);
 }
Example #3
0
 public ObjectWithTimerAwaitable(TaskCompletionSource tcs)
 {
     _tcs   = tcs;
     _timer = new TimerAwaitable(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1));
     _timer.Start();
 }
Example #4
0
 private void Start()
 {
     _nextHeartbeat.Start();
     _ = Task.Run(ExecuteTimerLoop); // Fire and forget the timer loop
 }