如何使用多请求和响应创建多线程?

时间:2013-10-01 13:40:37

标签: vb.net multithreading

Public Function getheaders(ByVal add As String) As String
    Dim req As WebRequest = WebRequest.Create("http://" & add)
    req.Timeout = 2000
    Try
        Using response As WebResponse = req.GetResponse()
            Dim aa As String = response.Headers("WWW-Authenticate")
            Return aa
          End Using
    Catch ex As WebException
        Using response As WebResponse = ex.Response
            If ex.Status.ToString = "Timeout" Then
                Return "none"
                Else
                Try
                    Dim aa As String = response.Headers("WWW-Authenticate")
                    Catch exa As Exception
                    Return "none"
                    End Try
            End If
        End Using
    End Try
End Function


//////////////////// CREATIN THREADS ///////////////////////

 For i = 0 To 255
        Dim t As Thread = New System.Threading.Thread(New ParameterizedThreadStart(AddressOf getheaders))
        t.IsBackground = True
        t.Start("192.168.1." & ai.ToString)
    Next

这个工作正常,但是当所有线程都完成后我再也无法使用互联网,等待5分钟或修复我的连接

哪里有错误或是否有另外的方法来做到这一点?

0 个答案:

没有答案