Skip to content

Instantly share code, notes, and snippets.

@skenderbeu
Created July 19, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skenderbeu/d9e7c257f2f774e4db592af9524dfb59 to your computer and use it in GitHub Desktop.
Save skenderbeu/d9e7c257f2f774e4db592af9524dfb59 to your computer and use it in GitHub Desktop.
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