Falling into exception "One or more errors occurred." Aggregate Exception

1.4k Views Asked by At

I am using parallel.foreach in my code to submit multiple url for my application. Initially it work fine but after few day I noticed this exception occurs often. I googled it for many hours but no luck for me.

Explaination: We have Api SMS system from where client submit sms to us and we submit to operators for bulksms. I have 10 URL to submit to specific operator File stop after few seconds with this error. Exception message: One or more errors occurred.

Below is my piece of code.

 Parallel.ForEach(urlList,
    Sub(state, line, index)

      If urlList(index).Sender.ToString = "" Then
          urlList(index).response = "ignore"
      Else
          urlList(index).response = SendHttpRequest(state.url.ToString)
      End If

      urlList(index).url = state.url
    End Sub)

and below is other function which submit HTTP Request.

Public Function SendHttpRequest(ByVal url As String) As String
    Dim responsetext As String = ""
    Try
        Dim webR As WebRequest = HttpWebRequest.Create(url)
        webR.Timeout = 40000
        Dim WebResponse As HttpWebResponse = TryCast(webR.GetResponse(), HttpWebResponse)
        Dim stream As Stream = WebResponse.GetResponseStream()
        Dim reader As New StreamReader(stream)
        responsetext = reader.ReadToEnd()
    Catch ex As Exception
        responsetext = ex.ToString() & vbCrLf
    End Try
    Return responsetext
End Function
0

There are 0 best solutions below