Example #1
0
    public async ValueTask DisposeAsync()
    {
        Exception?ex = null;

        for (int i = 0; i < RetryCount; i++)
        {
            try
            {
                Dir.DeleteEntireFolder();
            }
            catch (Exception e)
            {
                ex = e;
            }
            if (!Dir.Exists)
            {
                return;
            }
            await Task.Delay(Delay).ConfigureAwait(false);
        }
        if (ThrowIfUnsuccessfulDisposal && Dir.Exists)
        {
            if (ex != null)
            {
                throw ex;
            }
            throw new Exception($"Could not clean up temp directory: {Dir.Path}");
        }
    }