public static void DeleteFolderThatMayBeInUse(string folder)
{
if (Directory.Exists(folder))
{
try
{
RobustIO.DeleteDirectory(folder, true);
}
catch (Exception e)
{
try
{
Debug.WriteLine(e.Message);
//maybe we can at least clear it out a bit
string[] files = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories);
foreach (string s in files)
{
try
{
RobustFile.Delete(s);
}
catch (Exception)
{
}
}
//sleep and try again (in case some other thread will let go of them)
Thread.Sleep(1000);
RobustIO.DeleteDirectory(folder, true);
}
catch (Exception)
{
}
}
}
}