Created
July 19, 2018 18:46
-
-
Save skenderbeu/d9e7c257f2f774e4db592af9524dfb59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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