优化cancel

This commit is contained in:
nilaoda 2022-10-29 18:02:59 +08:00
parent 80f6aa7167
commit a13d3c1f7a
1 changed files with 2 additions and 2 deletions

View File

@ -64,7 +64,6 @@ namespace N_m3u8DL_RE.Util
if (speedContainer.ShouldStop) if (speedContainer.ShouldStop)
{ {
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
speedContainer.ResetLowSpeedCount();
Logger.DebugMarkUp("Cancel..."); Logger.DebugMarkUp("Cancel...");
break; break;
} }
@ -105,7 +104,7 @@ namespace N_m3u8DL_RE.Util
while ((size = await responseStream.ReadAsync(buffer, cancellationTokenSource.Token)) > 0) while ((size = await responseStream.ReadAsync(buffer, cancellationTokenSource.Token)) > 0)
{ {
speedContainer.Add(size); speedContainer.Add(size);
await stream.WriteAsync(buffer, 0, size); await stream.WriteAsync(buffer, 0, size, cancellationTokenSource.Token);
} }
return new DownloadResult() return new DownloadResult()
@ -117,6 +116,7 @@ namespace N_m3u8DL_RE.Util
} }
catch (OperationCanceledException oce) when (oce.CancellationToken == cancellationTokenSource.Token) catch (OperationCanceledException oce) when (oce.CancellationToken == cancellationTokenSource.Token)
{ {
speedContainer.ResetLowSpeedCount();
throw new Exception("Download speed too slow!"); throw new Exception("Download speed too slow!");
} }
} }