Skip to content

Commit

Permalink
delete directory (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc authored Feb 9, 2023
1 parent 1e6ee81 commit 37db03b
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions cs/test/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,20 @@ internal static void DeleteDirectory(string path, bool wait = false)
}
}

bool retry = true;
while (retry)
for (; ; Thread.Yield())
{
// Exceptions may happen due to a handle briefly remaining held after Dispose().
retry = false;
try
{
Directory.Delete(path, true);
}
catch (Exception ex) when (ex is IOException ||
ex is UnauthorizedAccessException)
{
if (!wait)
{
try { Directory.Delete(path, true); }
catch { }
return;
}
retry = true;
}
if (!wait || !Directory.Exists(path))
break;
}

if (!wait)
return;

while (Directory.Exists(path))
Thread.Yield();
}

/// <summary>
Expand Down

0 comments on commit 37db03b

Please sign in to comment.