A question about threads

looc

Member
Joined
Jan 4, 2008
Messages
8
Programming Experience
Beginner
Hi.

Im kind of new to vb.net and got curious about threads.

I have managed to do things in new threads but i want to know more.

I have a project i would like to do and the later expand to do other things, can someone help me out.

Lets say:
I have a list of IP-numbers lets say 500 addresses, xml or in a sql
I would like to check ping status of these addresses and i would like to check them fast so i would like to do this in multi-threads 10 -20 at the time.

I guess i could use the pool, so when one ip is checked the next one is on cue

When the ip is checked i would like to return the result to the db or just put it in a textfile.


So, can this be done easily in vb.net 2008 or does it take a lot of code to be implemented?

Thanks for any help /Bjorn
 
You'll get much better performance using the asynchronous SendAsync method of Ping class. Something like this:
VB.NET:
'Imports System.Net.NetworkInformation

Sub pinging()
    For Each ip As String In yourIPlist
        Dim p As New Ping
        AddHandler p.PingCompleted, AddressOf p_PingCompleted
        p.SendAsync(ip, 1000, Nothing)
    Next
End Sub

Private Sub p_PingCompleted(ByVal sender As Object, ByVal e As PingCompletedEventArgs)
    DirectCast(sender, IDisposable).Dispose()
    If e.Error Is Nothing AndAlso e.Reply.Status = IPStatus.Success Then
        Dim ip As String = e.Reply.Address.ToString
    End If
End Sub
 
ok thanks

but i need more code, more ore less a working example ..

i'm a beginner in .net so i know this is i bit over my pay grade, but i'm curious to how it works

in this example you are sending one attribute, the ip, but how do i send more attributes and have them folow the process all the way to the last function where i can write the result back to db

Thanks
/Bjorn
 
The last parameter of SendAsync where I put "Nothing" is the userToken of Object type. Here you can put anything and retrieve it from e.UserState in PingCompleted event.
 
Back
Top