0
我有一個字符串,它包含我想要下載的多個圖片的URL,我將這個字符串分開並將每個URL存儲在一個數組中,然後在數組中循環以獲取每個URL並下載它,但應用程序一直掛起,直到完成所有事件。這是我的代碼:當瀏覽器正在下載文件時,應用程序掛起
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim cnt As Integer = 1
Dim singleUrl As String() = allPicsURL.Split(New Char() {","c})
ReDim Preserve singleUrl(UBound(singleUrl) - 1)
For j As Integer = 0 To singleUrl.Length() - 1
My.Computer.Network.DownloadFile(singleUrl(j), "F:\Users\Dany\Pictures\Test\" & Date.Now().ToFileTime & ".jpeg")
cnt += 1
Next
MsgBox(cnt - 1 & " Pictures were saved!", MsgBoxStyle.OkOnly)
End Sub
如何阻止我的應用程序凍結?
你是如何開始你的後臺工作?你是否像這樣做BackgroundWorker1.RunWorkerAsync() –
你可以使用backgoround工作人員 – TOM
上的按鈕單擊:BackgroundWorker1_DoWork(sender,Nothing), 我將它更改爲.RunWorkerAsync()? –