using System; | |
using System.IO; | |
using Polly; | |
namespace SpreadsheetImporter | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ReadFile(@"C:\temp\jam2.xls"); | |
Console.ReadLine(); | |
} | |
private static void ReadFile(string filePath) | |
{ | |
var policy = Policy | |
.Handle<IOException>() | |
.WaitAndRetry(new[] | |
{ | |
TimeSpan.FromSeconds(10), | |
TimeSpan.FromSeconds(20), | |
TimeSpan.FromSeconds(30) | |
}, (exception, timeSpan) => { | |
Console.WriteLine("Please Close the file and try again"); | |
}); | |
try | |
{ | |
policy.Execute(() => Console.WriteLine(ReadAllText(filePath))); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine($"Something has gone wrong, see exception message: {ex.Message}"); | |
} | |
} | |
private static string ReadAllText(string filePath) | |
{ | |
return $"Content of file is: {File.ReadAllText(filePath)}"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment