2011-10-28 4 views
0

사용자가 양식에서 선택한 내용을 기반으로 여러 파일을 다운로드하려고합니다. 여러 개의 확인란이 있으므로 사용자가 확인란 1,3,4를 선택하면 웹 클라이언트가 1.txt, 3.txt, 4.txt 파일을 다운로드해야합니다. WebClient 메서드로 인해 "WebClient에서 동시 I/O 작업을 지원하지 않습니다." 오류.VB - 여러 다운로드에 DownloadFileASync (WebClient) 사용

If chk1.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/1.txt), Path.Combine(DataSource & strDirectory, "1.txt")) 
    End If 
If chk2.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/2.txt), Path.Combine(DataSource & strDirectory, "2.txt")) 
    End If 
If chk3.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/3.txt), Path.Combine(DataSource & strDirectory, "3.txt")) 
    End If 
If chk4.Checked Then 
     WC.DownloadFileAsync(New Uri("http://www.google.com/4.txt), Path.Combine(DataSource & strDirectory, "4.txt")) 
    End If 

다운로드를 추적하는 진행률 막대와 메시지 상자를 호출하는 완료된 이벤트가 있습니다.

Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged 
    ProgressBar1.Value = e.ProgressPercentage 

End Sub 
Private Sub WC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted 
    MessageBox.Show("Download complete", "Download", MessageBoxButtons.OK, MessageBoxIcon.Information) 
End Sub 

어떻게 체크하면 모든 파일을 다운로드 할 수 있습니까? 사용자가 전체 파일 다운로드 또는 남은 시간을 보여주는 진행률 막대 만 보더라도 모든 다운로드가 완료되면 표시 할 항목이 필요합니까?

제안 사항?

답변

2

저는 여러 WebClient 인스턴스를 사용하여 동시에 여러 HTTP 요청을 실행한다고 생각합니다. 여러 인스턴스를 사용해보십시오.

관련 문제