private static bool RetryInProgress { get; set; } = false;
public static async Task UploadFileWithRetryAsync()
{
Console.WriteLine($"Start UploadFileWithRetryAsync");
if (RetryInProgress)
{
Console.WriteLine($"Retrying");
return;
}
RetryInProgress = true;
for (int i = 0; i < 7; i++)
{
if (i != 0)
{
int waitTimeInSeconds = (int)Math.Pow(2, i - 1);
Console.WriteLine($"Waiting for {waitTimeInSeconds} seconds...");
await Task.Delay(TimeSpan.FromSeconds(waitTimeInSeconds));
}
try
{
Console.WriteLine($"Trying {i + 1}");
using (var stream = new FileStream(LocalFilePath, FileMode.Open))
{
await UploadFileAsync(stream, RemoteFileName);
break;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
RetryInProgress = false;
Console.WriteLine($"End UploadFileWithRetryAsync");
}
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme