dotnet / dotnet/winforms

My.Computer.Network.DownloadFile does not cancel immediately

Open
#10,709 7 comments 0 reactions 0 assignees View on GitHub
area-VisualBasic priority-3
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### .NET version

Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.9.0 Preview 3.0

### Did it work in .NET Framework?

Yes

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

Don't think so

### Issue description

When you download a large file with a progress UI, and then cancel the request through UI the download completes and then the cancel error is thrown. Also, on Framework the partially download file is deleted and .NET Core the fully download file is left in the destination directory.

The code below is a test, it is includes and 3 PR's

```

Public Sub DownloadWithUI()
Dim tmpFilePath As String = CreateTempDirectory()
Dim destinationFilename As String = CreateTempFile(tmpFilePath, 0)
My.Computer.Network.DownloadFile("https://ash-speed.hetzner.com/100MB.bin",
destinationFilename,
"",
"",
True,
100000,
True
)
Assert.Equal(ValidateDownLoad(tmpFilePath, destinationFilename), 104857600)
CleanupTempDirectory(tmpFilePath)
End Sub
```

### Steps to reproduce

Download a large file with UI using My.Computer.Network.DownloadFile and the cancel operation.
Download will complete before CancelOperation is thrown and resulting file is in destination directory, in Framework cancel is immediate and file is deleted.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.