Skip to content

Commit

Permalink
优化cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed Oct 29, 2022
1 parent 80f6aa7 commit a13d3c1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/N_m3u8DL-RE/Util/DownloadUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static async Task<DownloadResult> DownloadToFileAsync(string url, string
if (speedContainer.ShouldStop)
{
cancellationTokenSource.Cancel();
speedContainer.ResetLowSpeedCount();
Logger.DebugMarkUp("Cancel...");
break;
}
Expand Down Expand Up @@ -105,7 +104,7 @@ public static async Task<DownloadResult> DownloadToFileAsync(string url, string
while ((size = await responseStream.ReadAsync(buffer, cancellationTokenSource.Token)) > 0)
{
speedContainer.Add(size);
await stream.WriteAsync(buffer, 0, size);
await stream.WriteAsync(buffer, 0, size, cancellationTokenSource.Token);
}

return new DownloadResult()
Expand All @@ -117,6 +116,7 @@ public static async Task<DownloadResult> DownloadToFileAsync(string url, string
}
catch (OperationCanceledException oce) when (oce.CancellationToken == cancellationTokenSource.Token)
{
speedContainer.ResetLowSpeedCount();
throw new Exception("Download speed too slow!");
}
}
Expand Down

0 comments on commit a13d3c1

Please sign in to comment.