【问题标题】:how to set progressbar while downloading file from ftp从ftp下载文件时如何设置进度条
【发布时间】:2014-04-07 08:42:52
【问题描述】:

以下代码用于从driveHq下载exe文件

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
        Dim strFTPpath, strDestPath As String
        Cursor.Current = Cursors.WaitCursor
        'strFTPpath is the url of where Latest upd is located
        'strDestPath is system path to dwonload upd from FTP
        strFTPpath = "ftp://MYUSRNAM:MYPWD@ftp.drivehq.com/rstari9kremcos/RStari9.exe"
        strDestPath = "D:\Rstari9\GDS\RStari9.exe"
        My.Computer.Network.DownloadFile(strFTPpath, strDestPath)
        Cursor.Current = Cursors.Arrow
        Button1.Enabled = False
        MsgBox("latest updation successfully downloaded to 'D:\Rstari9\GDS\RStari9.exe'", MsgBoxStyle.Information, "RStari9 - Download Success")
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Information, "Update downloading aborted...")
    End Try
End Sub

this is my UI to download,我想在其中添加一个进度条

代码:VB.NET

【问题讨论】:

  • 不要在 UI 线程中执行此操作,否则它会在完成之前停止您的 UI。使用 BackgroundWorker。使用 DownloadFile(),您将不会收到有关下载状态的通知,因此您无法显示进度条(除非您只想要一个选取框)。您可以做的是将 showUi 参数设置为 true。
  • @Adriano 有什么例子吗??
  • 试试this,这不是你在做什么,但它会解释技术。

标签: c# vb.net download


【解决方案1】:

My.Computer.Network.DownloadFile 有一个名为showUI 的参数,您可以将其设置为True 以显示操作的进度。 您可以通过这种方式更改您的代码:

My.Computer.Network.DownloadFile(strFTPpath, strDestPath, "", "", True, 100000, False)

不幸的是,My.Computer.Network.DownloadFile 没有异步下载文件的方法,所以如果你想开发自己的 UI,就必须使用其他东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多