Aspectacular.RetryAspectBase.SetRetryIfNecessary C# (CSharp) Method

SetRetryIfNecessary() protected method

protected SetRetryIfNecessary ( bool mayNeedToRetry ) : void
mayNeedToRetry bool
return void
        protected virtual void SetRetryIfNecessary(bool mayNeedToRetry)
        {
            if(!mayNeedToRetry || this.NeedToStopRetries())
                return;

            this.Proxy.ShouldRetryCall = true;

            if(this.Proxy.AttemptsMade == 1)
            {
                this.LogInformationData("Retrying", true);
                this.BeforeFirstRetry();
            }

            object logData = this.Proxy.MethodExecutionException ?? this.Proxy.ReturnedValue;
            this.LogInformationData("Retry Cause", logData);

            if(this.MillisecDelayBetweenRetries > 0)
            {
                this.LogInformationWithKey("Retry delay", "{0:#,#0}", this.MillisecDelayBetweenRetries);

                if(Threading.Sleep(this.MillisecDelayBetweenRetries) == SleepResult.Aborted)
                {
                    // Application exiting. Abort retry loop.
                    this.Proxy.ShouldRetryCall = false;
                    this.LogInformationData("Retry Aborted", true);
                    return;
                }
            }

            this.LogInformationData("Retry Attempt", this.Proxy.AttemptsMade);
        }