void ExecutePollingLoop(object ignored) { var retry = RetryPolicy.Create(); var sleepFor = TimeSpan.Zero; while (working) { try { try { retry.Try(); secureClient.ExecuteTransaction(protocol => { protocol.ExchangeAsSubscriber(subscription, handleIncomingRequest); }, cancellationToken); retry.Success(); } finally { sleepFor = retry.GetSleepPeriod(); } } catch (HalibutClientException ex) { log?.WriteException(EventType.Error, $"Halibut client exception: {ex.Message?.TrimEnd('.')}. Retrying in {sleepFor.TotalSeconds:n1} seconds", ex); } catch (Exception ex) { log?.WriteException(EventType.Error, $"Exception in the polling loop. Retrying in {sleepFor.TotalSeconds:n1} seconds. This may be cause by a network error and usually rectifies itself. Disregard this message unless you are having communication problems.", ex); } finally { Thread.Sleep(sleepFor); } } }