r/visualbasic • u/Zenith2012 • Mar 04 '22
VB.NET Help How to check if clients are online without holding up the application
Hi all,
I have a simple application that loads a list of windows clients from active directory into a list view control. What I want to do is ping them to check if they are online or not, I'm currently using the following function for that:
Public Function ClientOnline(ByVal sHostName As String) As Boolean
Try
If My.Computer.Network.Ping(sHostName) Then
ClientOnline = True
Else
ClientOnline = False
End If
Catch
ClientOnline = False
End Try
End Function
The issue I'm having is that this locks up the application whilst all the clients are pinged. I'm looking for help in moving this ping request into it's own process that doesn't lock up the main application. Ideally I would like to be able to control how many of these processes are running at once so I don't just fire off a large number of them if there are 100+ clients on the network.
Any help is greatly appreciated.
Thanks
6
u/sa_sagan VB.Net Master Mar 04 '22
What happens when the ping is successful or not?
I assume you're fairly newish to this stuff so you could just have the pinging done in a BackgroundWorker and have the BackgroundWorker update whatever needs updating. It'll run in a separate thread in your application and won't hang it. Have the worker loop through your list.
4
u/Hel_OWeen Mar 04 '22
What you are looking for is (System.)Threading.
See e.g. this example