vb.net 多线程運用 ping

前端之家收集整理的这篇文章主要介绍了vb.net 多线程運用 ping前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Imports System.IO
Imports System.Threading
Imports System.Diagnostics

Public Class Form1

Dim A(254) As String

 

 Function ping(ByVal IP As Integer) As String

Dim IPAddress As String
IPAddress = "10.0.2." & IP
If My.Computer.Network.Ping(IPAddress) Then
A(IP) = "OK"
Else
A(IP) = "NG"
End If
End Function

 

Private Sub Button1_Click_1(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click

Dim mythread(254) As Thread

Dim i As Integer
‘创建线程对象

For i = 1 To 254
mythread(i) = New Thread(AddressOf ping)
Next

‘执行线程
For i = 1 To 254
mythread(i).Start(i)
Next

‘等待线程完成
For i = 1 To 254
mythread(i).Join()
TextBox1.Text = A(i)

Next

End Sub

 

End Class

原文链接:/vb/802168.html

猜你在找的VB相关文章