I searched in the internet for the solution, and i found one but i want to edit the function, is there a way to cancel it without editing anything??
for example Await ytclient.Videos.Streams.DownloadAsync.Close?? (VB.Net)
Any help would be appreciated?
I think what You looking for is here:
https://github.com/Tyrrrz/YoutubeExplode/blob/2daf378c1368af5dd7c427858b1a53e4f4cd5113/YoutubeExplode/Videos/Streams/StreamsClient.cs#L308-L309
To be more specific is the CancellationToken parameter.
Here is an untested but hopefully working solution how to cancel the download by creating a new CancellationTokenSource an passing its token to the DownloadAsync method.
There is an example of cancellation in the DemoWpf project.
Thanks to everyone i made it by myself but In VB.Net
Here is the code , if anyone is struggling with that.
-Add the following code at the start of the form
Dim cts As New CancellationTokenSource
-Add button and add the following code to it
If cts IsNot Nothing Then
cts.Cancel()
End If
-The last thing you want to add Try statement because of out it, the program will crash
Try
Await ytclient.Videos.Streams.DownloadAsync(streamInfo, "Hi.mp4", progress, cts.Token)
Catch ex As Exception
MessageBox.Show("cancelled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Enjoy!!!
Good job!