private void DeleteFileWithRetry(string filename)
{
bool done = false;
int nRetries = 3;
for (int i=0; i < nRetries && !done; i++)
{
try
{
File.Delete(filename);
done = true;
}
catch (System.UnauthorizedAccessException)
{
Console.WriteLine("************************************************** Retry delete.");
System.Threading.Thread.Sleep(200+i*200);
}
}
}