Puoi provare così
Public Class Form1
Private Const ping_timeout_ms As Integer = 500
Private test(254) As Boolean
Private bg2_completed As Boolean = False
Private bg3_completed As Boolean = False
Private bg4_completed As Boolean = False
Private my_net As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ip() As Byte = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList(0).GetAddressBytes()
my_net = ip(0).ToString & "." & ip(1).ToString & "." & ip(2).ToString & "."
BackgroundWorker1.RunWorkerAsync()
BackgroundWorker2.RunWorkerAsync()
BackgroundWorker3.RunWorkerAsync()
BackgroundWorker4.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i As Integer = 1 To 253 Step 4
If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
test(i) = True
Else
test(i) = False
End If
Next
End Sub
Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
For i As Integer = 2 To 254 Step 4
If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
test(i) = True
Else
test(i) = False
End If
Next
bg2_completed = True
End Sub
Private Sub BackgroundWorker3_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker3.DoWork
For i As Integer = 3 To 251 Step 4
If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
test(i) = True
Else
test(i) = False
End If
Next
bg3_completed = True
End Sub
Private Sub BackgroundWorker4_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker4.DoWork
For i As Integer = 4 To 252 Step 4
If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
test(i) = True
Else
test(i) = False
End If
Next
bg4_completed = True
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
While Not (bg2_completed And bg3_completed And bg4_completed)
System.Threading.Thread.Sleep(100)
End While
For i As Integer = 1 To 254
If test(i) Then
ComboBox1.Items.Add(my_net & i.ToString)
Else
ComboBox2.Items.Add(my_net & i.ToString)
End If
Next
MsgBox("Lista caricata!")
End Sub
End Class