public byte[] Get(Coord coord, string format)
{
string path = this.buildPath(coord, format);
byte[] img = null;
int i = 0;
while (true)
{
try
{
img = File.ReadAllBytes(path);
break;
}
catch (FileNotFoundException e) { break; }
catch (DirectoryNotFoundException e) { break; }
catch (IOException e)
{
//is file being written? check for ERROR_SHARING_VIOLATION (HRESULT = -2147024864)
//.NET 4.5 required to access HResult directly
if (e.HResult == -2147024864 && i <= ACCESS_POLL_COUNT)
{
i++;
Thread.Sleep(ACCESS_POLL_INTERVAL);
}
else
{
throw;
}
}
}
return img;
}