Vb.net 下载从数组url获取的文件列表

Vb.net 下载从数组url获取的文件列表,vb.net,download,Vb.net,Download,我的代码有问题。拿一个代表一些文件名的字符串数组,我会一个接一个地下载它们并添加到我的进度条中。当我运行时,代码文件会被下载,但GUI不会在标签中更新,也不会加载条。只有当程序退出时,循环才会在外部运行代码。将带有+4的接口更新到条形图。在每次下载文件后,如何更新增加6的条?我错在哪里?下载时更新冻结界面 Private Sub patchButton_Click(sender As Object, e As EventArgs) Handles patchButton.Click Di

我的代码有问题。拿一个代表一些文件名的字符串数组,我会一个接一个地下载它们并添加到我的进度条中。当我运行时,代码文件会被下载,但GUI不会在标签中更新,也不会加载条。只有当程序退出时,循环才会在外部运行代码。将带有+4的接口更新到条形图。在每次下载文件后,如何更新增加6的条?我错在哪里?下载时更新冻结界面

Private Sub patchButton_Click(sender As Object, e As EventArgs) Handles patchButton.Click
    Dim fileDownload(15) As String
    fileDownload(0) = "icon.eix"
    fileDownload(1) = "icon.epk"
    fileDownload(2) = "locale_tr.epk"
    fileDownload(3) = "locale_tr.eix"
    fileDownload(4) = "Metin2_patch_ZodiakMaps.eix"
    fileDownload(5) = "Metin2_patch_ZodiakMaps.epk"
    fileDownload(6) = "metin2_patch_ZodiakMonster.eix"
    fileDownload(7) = "metin2_patch_ZodiakMonster.epk"
    fileDownload(8) = "metin2_patch_ZodiarkArmor.eix"
    fileDownload(9) = "metin2_patch_ZodiarkArmor.epk"
    fileDownload(10) = "metin2_patch_ZodiarkEffect.eix"
    fileDownload(11) = "metin2_patch_ZodiarkEffect.epk"
    fileDownload(12) = "metin2_patch_ZodiarkWeapon.eix"
    fileDownload(13) = "metin2_patch_ZodiarkWeapon.epk"
    fileDownload(14) = "root.eix"
    fileDownload(15) = "root.epk"

    For Each item As String In fileDownload
        consoleLabel.Text = "Update " + item + "..."
        If My.Computer.FileSystem.FileExists(currentPath + "\pack\" + item) Then
            My.Computer.FileSystem.DeleteFile(currentPath + "\pack\" + item)
            My.Computer.Network.DownloadFile(urlResource + item, currentPath + "\pack\" + item)
            ProgressBar1.Value = +6
            If My.Computer.FileSystem.FileExists(currentPath + "\pack\" + item) Then
                consoleLabel.Text = item + "Aggiornato Correttamente"
                ProgressBar1.Value = +6
            End If
        Else
            My.Computer.Network.DownloadFile(urlResource + item, currentPath + "\pack\" + item)
            consoleLabel.Text = item + "Update Success"
            ProgressBar1.Value = +6
        End If
    Next
    ProgressBar1.Value = +4
    consoleLabel.Text = "The Client is Update"
    consoleLabel.ForeColor = Color.Green
    patchButton.Enabled = False
    startClient.Enabled = True
    startClient.BackColor = Color.Orange
    My.Computer.FileSystem.DeleteFile(currentPath + "\" + versionFile)
    My.Computer.FileSystem.WriteAllText(currentPath + "\" + versionFile, versionServer, False)
    versionLabel.Text = "Version: " + My.Computer.FileSystem.ReadAllText(currentPath + "\" + versionFile)
    Me.Update()
End Sub

您可以使用Application.DoEvents()或BackgroundWorker控件来完成该过程并更新用户界面。为了使用BackgroundWorker,您至少应该学习一些关于多线程的知识。是关于Application.DoEvents()的信息,是关于BackgroundWorker的信息。但是,在后台工作人员需要插入下载操作或更新用户界面操作吗?是。您需要使用Network.DownloadFile命令并更改BackgroundWorker的DoWork()事件中ProgressBar的值,还需要使用Invoke()方法更新用户界面。