Microsoft.Azure.WebJobs.Script.IO.AutoRecoveringFileSystemWatcher.Recover C# (CSharp) Method

Recover() private method

private Recover ( int attempt = 1 ) : Task
attempt int
return Task
        private async Task Recover(int attempt = 1)
        {
            // Exponential backoff on retries
            long wait = Convert.ToInt64((Math.Pow(2, attempt) - 1) / 2);

            // maximum wait of 5 minutes
            wait = Math.Min(wait, 300);

            if (wait > 0)
            {
                Trace($"Next recovery attempt in {wait} seconds...", TraceLevel.Warning);
                await Task.Delay(TimeSpan.FromSeconds(wait)).ConfigureAwait(false);
            }

            // Check if cancellation was requested while we were waiting
            _cancellationToken.ThrowIfCancellationRequested();

            try
            {
                ReleaseCurrentFileWatcher();
                InitializeWatcher();
            }
            catch (Exception exc) when (!(exc is TaskCanceledException) && !exc.IsFatal())
            {
                Trace($"Unable to recover - {exc.ToString()}", TraceLevel.Error);

                await Recover(++attempt);
            }
        }