Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
吞掉取消任务的异常
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed Jun 5, 2020
1 parent 0cd1d62 commit d1eb27f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,21 @@ public static async Task<MemoryStream> DownloadImage(string Uri, CancellationTok
var bytesCounter = 0L;
int bytesRead;
byte[] buffer = new byte[4096];
while ((bytesRead = await resStream.ReadAsync(buffer, 0, 4096, CancellationToken)) != 0)
try
{
PauseEvent?.WaitOne();
bytesCounter += bytesRead;
await memStream.WriteAsync(buffer, 0, bytesRead, CancellationToken);
_ = ProgressCallback?.Invoke(bytesCounter, length);
while ((bytesRead = await resStream.ReadAsync(buffer, 0, 4096, CancellationToken)) != 0)
{
PauseEvent?.WaitOne();
bytesCounter += bytesRead;
await memStream.WriteAsync(buffer, 0, bytesRead, CancellationToken);
_ = ProgressCallback?.Invoke(bytesCounter, length);
}
}
catch (TaskCanceledException)
{ }
catch
{
throw;
}
memStream.Position = 0;
var newCachedFile = await CacheManager.CreateCacheFileAsync(tmpFileName);
Expand Down

0 comments on commit d1eb27f

Please sign in to comment.