CancelAsync()之后的Webclient下载问题

时间:2019-06-27 08:58:25

标签: vb.net webclient

我有一个Web客户端,可以下载Facebook视频,并且拥有它,以便用户可以取消下载,但是由于某些奇怪的原因,当我调用我的cancel方法并尝试下载另一个文件时,它什么也没做。就像cancel方法破坏了webclient一样,我在做什么错?它确实引发错误,我猜这是导致它损坏的原因...

我已经尝试了一切,但仍然不知道为什么会发生

这是数据下载完成时的代码。

Dim filedata As Byte() = e.Result
Dim datafile As String = save_path & "\" & facebook_id & ".mp4"

If cancelled = False Then

     Notify.ShowBalloonTip(5000, "", "Video Successfully Downloaded!", ToolTipIcon.Info)
     SMCT_Box.Text = ""

Else

     Notify.ShowBalloonTip(5000, "", "Download Cancelled!", ToolTipIcon.Info)

End If

Using fileStream As FileStream = New FileStream(datafile, FileMode.Create)

     fileStream.Write(filedata, 0, filedata.Length)

     If File.Exists(datafile) Then

          If cancelled = False Then

              Tool_Tip.SetToolTip(Download_Button, "Download")
              Download_Button.Text = "Download"
              progress = 0
              TaskbarManager.Instance.SetProgressValue(0, 100)

          End If

    End If

End Using

If cancelled = True Then

     File.Delete(datafile)
     cancelled = False

End If

If cancelled = False Then

     If My.Settings.include_thumbnail = True Then

         SaveThumbnail(thumbnail_link, thumbnail_id)

     End If

     If My.Settings.file_type = "mp3" Then

          Dim message As String = "Converting Please Wait..."
          MessageBox.Show(message, "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information)

          Dim converter As New Process
          converter.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
          converter.StartInfo.CreateNoWindow = True
          converter.StartInfo.FileName = app_path & "\Converter.exe"
          converter.Start()
          converter.WaitForExit()

          If converter.HasExited = True Then

              If My.Settings.open_after_download = True Then

                  Process.Start(save_path & "\" & facebook_id & ".mp3")

              End If

              If My.Settings.create_backup = True Then

                  My.Computer.FileSystem.CopyFile(save_path & "\" & facebook_id & ".mp3", app_path & "\Backups\" & facebook_id & ".mp3")

              End If

         End If

    Else

         If My.Settings.create_backup = True Then

              My.Computer.FileSystem.CopyFile(save_path & "\" & facebook_id & ".mp4", app_path & "\Backups\" & facebook_id & ".mp4")

         End If

    End If

    If My.Settings.open_after_download = True Then

         Process.Start(save_path & "\" & facebook_id & ".mp4")

    End If

End If


这是cancel方法的代码。

cancelled = True
facebook.CancelAsync()
facebook.Dispose()

DGV.Rows.Remove(DGV.SelectedRows(rows - 1))
rows -= 1

Tool_Tip.SetToolTip(Download_Button, "Download")
Download_Button.Text = "Download"
Thumbnail_Box.Image = Nothing
Thumbnail_Error_Label.Visible = True
progress = 0
TaskbarManager.Instance.SetProgressValue(0, 100)

0 个答案:

没有答案
相关问题