bezzad / Downloader

Fast, cross-platform and reliable multipart downloader with asynchronous progress events for .NET applications.
MIT License
1.25k stars 193 forks source link

The CancelTaskAsync interface of IDownloadService causes the program to freeze. #157

Closed Gilfoylex closed 6 months ago

Gilfoylex commented 6 months ago

This is the implementation of the CancelTaskAsync interface in DownloadService.cs.

public async Task CancelTaskAsync()
{
        CancelAsync();
        await Task.Yield(); // prevents a sync/hot thread hangup
        if (_taskCompletion is not null)
             await _taskCompletion.Task;
}

The CancelAsync(); function does not call _taskCompletion.TrySetCanceled() or _taskCompletion.TrySetResult(e) on _taskCompletion, so await _taskCompletion.Task will hang indefinitely.

Gilfoylex commented 6 months ago

can not call CancelTaskAsync on ui thread