读书人

vb.net多线程

发布时间: 2012-09-22 21:54:54 作者: rapoo

vb.net多线程求助
手头有批路由器,都能正常访问,现在想利用多线程加快访问和处理路由器相关页面,如判断路由器是否在线等?、
思路:
for i=0 to ipCount-1 '////ipCount是路由器数量
t1 '建立和启动线程,t1处理A页面
t2 '建立和启动线程,t2处理B页面
t3 '建立和启动线程,t3处理C页面
t1.join
t2.join
t3.join
next
这样与单线程效率相差不多。

[解决办法]
大概思路如下,具体的跟你自己的情况改下吧:

VB.NET code
        Dim tClientThread As Thread = Nothing        Dim strURL As String = ""        For i As Integer = 0 To ipCount - 1 '////ipCount是路由器数量            tClientThread = New Thread(AddressOf ClientProcess) '创建线程            Select Case i                Case 1                    strURL = "url1=http://IP/a.html"                Case 2                    strURL = "url1=http://IP/b.html"                Case 3                    strURL = "url1=http://IP/c.html"            End Select            tClientThread.Start(strURL) '启动线和并传递参数数据        Next    '------------------------------    Public Sub ClientProcess(ByVal MyData As Object) '处理连接过程        Dim strURL As String = CType(MyData, String) '线程传入的网址串        Try            '这是你的连接代码        Catch ex As Exception            MsgBox(ex.Message, MsgBoxStyle.Critical, "错误信息")        End Try    End Sub 

读书人网 >VB Dotnet

热点推荐