Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27071

[VB.NET] Multithreading a large number of web requests

$
0
0
Private Sub threadimportbtcUSD()

Do
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://btc-e.com/api/2/btc_usd/depth"), HttpWebRequest)

Try

Dim risposta As String
postReq.ServicePoint.ConnectionLimit = connectionlimit
postReq.Timeout = 5000
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
risposta = postreqreader.ReadToEnd.Replace(Chr(34), Chr(39))
postresponse.Close()
postreqreader.Close()
postReq.Abort()

Catch ex As Exception
postReq.Abort()
End Try

Thread.Sleep(1000)
Loop
End Sub


I am using the code above on 20 different threads simultaneously, each one submit requests to a different http address. It works for a while, then all requests start to timeout and the only way i can have the project work again is by switching my router off and on. How can i solve this problem?

Viewing all articles
Browse latest Browse all 27071


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>