Ejemplo n.º 1
0
 private void StartPolling(CancellationToken cancellationToken)
 {
     Task.Factory.StartNew(async() =>
     {
         int retry = 0;
         while (!cancellationToken.IsCancellationRequested)
         {
             if (!_httpUri.Contains("&sid="))
             {
                 await Task.Delay(20);
                 continue;
             }
             try
             {
                 await _httpPollingHandler.GetAsync(_httpUri, CancellationToken.None).ConfigureAwait(false);
             }
             catch (Exception e)
             {
                 retry++;
                 if (retry >= 3)
                 {
                     MessageSubject.OnError(e);
                     break;
                 }
                 await Task.Delay(100 * (int)Math.Pow(2, retry));
             }
         }
     }, TaskCreationOptions.LongRunning);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// <para>Eio3 ping is sent by the client</para>
 /// <para>Eio4 ping is sent by the server</para>
 /// </summary>
 /// <param name="cancellationToken"></param>
 private void StartPing(CancellationToken cancellationToken)
 {
     _logger.LogDebug($"[Ping] Interval: {OpenedMessage.PingInterval}");
     Task.Factory.StartNew(async() =>
     {
         while (!cancellationToken.IsCancellationRequested)
         {
             await Task.Delay(OpenedMessage.PingInterval);
             if (cancellationToken.IsCancellationRequested)
             {
                 break;
             }
             try
             {
                 var ping = new PingMessage();
                 _logger.LogDebug($"[Ping] Sending");
                 await SendAsync(ping, CancellationToken.None).ConfigureAwait(false);
                 _logger.LogDebug($"[Ping] Has been sent");
                 _pingTime = DateTime.Now;
                 MessageSubject.OnNext(ping);
             }
             catch (Exception e)
             {
                 _logger.LogDebug($"[Ping] Failed to send, {e.Message}");
                 MessageSubject.OnError(e);
                 break;
             }
         }
     }, TaskCreationOptions.LongRunning);
 }
Ejemplo n.º 3
0
 public void OnError(Exception error)
 {
     MessageSubject.OnError(error);
 }