Skip to content

Commit

Permalink
GC optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Nov 20, 2021
1 parent 390d56b commit 6c7d419
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public static async Task AdvancedDownloadListFile(IEnumerable<DownloadFile> file
actionBlock.Complete();

GC.Collect();
GC.WaitForPendingFinalizers();
}

#endregion
Expand Down Expand Up @@ -303,7 +304,7 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, i
p =>
{
using var request = new HttpRequestMessage
{ RequestUri = new Uri(downloadFile.DownloadUri) };
{ RequestUri = new Uri(downloadFile.DownloadUri) };

if (!string.IsNullOrEmpty(downloadFile.Host))
request.Headers.Host = downloadFile.Host;
Expand Down Expand Up @@ -372,8 +373,6 @@ public static async Task MultiPartDownloadTaskAsync(DownloadFile downloadFile, i

Interlocked.Add(ref tasksDone, 1);
doneRanges.TryTake(out _);

GC.Collect();
}, new ExecutionDataflowBlockOptions
{
BoundedCapacity = numberOfParts,
Expand Down Expand Up @@ -435,15 +434,15 @@ await writeActionBlock.Completion.ContinueWith(async task =>
writeActionBlock.Complete();

#endregion

GC.Collect();
}
catch (Exception ex)
{
downloadFile.Completed?.Invoke(null,
new DownloadFileCompletedEventArgs(false, ex, downloadFile, 0));
foreach (var piece in readRanges.Where(piece => File.Exists(piece.TempFileName)))
File.Delete(piece.TempFileName);

downloadFile.Completed?.Invoke(null,
new DownloadFileCompletedEventArgs(false, ex, downloadFile, 0));

}
}

Expand Down

0 comments on commit 6c7d419

Please sign in to comment.