why i always got error like this "Exception has been thrown by the target of an invocation.".. its didnt show which part code that got error occur..
here my code..
Class WC
Inherits WebClient
Friend Address As Uri
Friend FileName As String
Friend Progress As Integer
End Class
Dim WCs As New List(Of WC)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For L As Integer = 0 To DataGridView2.RowCount - 1
Dim S(3) As String
For M As Integer = 0 To S.Length - 1
S(M) = DataGridView2.Item(M, L).Value.ToString
Next
If Not S(2) = "ERROR" Then Continue For
Button1.Enabled = False
WCs.Add(New WC)
AddHandler WCs(L).DownloadProgressChanged, AddressOf WCs_ProgressChanged
AddHandler WCs(L).DownloadFileCompleted, AddressOf WCs_DownloadCompleted
WCs(L).Address = New Uri(S(3))
WCs(L).FileName = S(0)
Dim D As String = CurDir() & "\update"
If Not Directory.Exists(D) Then Directory.CreateDirectory(D)
D = Path.Combine(D, S(0) & ".rar")
WCs(L).DownloadFileAsync(WCs(L).Address, D)
Next
End Sub
Sub WCs_ProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
DirectCast(sender, WC).Progress = e.ProgressPercentage
ProgressBar1.Value = 0
For Each WC As WC In WCs
ProgressBar1.Value += WC.Progress
Next
End Sub
Sub WCs_DownloadCompleted(sender As Object, e As AsyncCompletedEventArgs)
Dim WC As WC = DirectCast(sender, WC)
Dim Msg As String
If e.Error Is Nothing Then
Msg = WC.FileName + " downloaded sucessfully"
Else
Msg = "Error downloading " + WC.FileName
End If
WCs.Remove(WC) WC.Dispose()
If WCs.Count = 0 Then
Button1.Enabled = True
MessageBox.Show("Download Completed")
End If
End Sub