yes, I'm looking for examples for multithread apps
I would like to send a lot of pings in a great network and collect the
answers.
Pinging in sequence that would take a lot of time. I would like to
multithread this. I'm sure I've seen an example, but I can't find it now.
Do you know some place to find examples for that?
Not off the top of my head. It would be relatively easy to write one, but
I don't think you really want to do this using threading. The Ping class
has a usable asynchronous API, which I think you should use. You can
subscribe to the PingCompleted event to receive notification of the
completion of pings that you've initiated using the SendAsync() method.
You can only have one uncompleted ping per Ping instance, so you'd want to
create the same number of Ping instances as the number of simultaneous
started-but-uncompleted pings you want. I suspect that doing it this way
will perform better and use less resources than creating a new thread for
each ping, or assigning the ping to a thread pool thread (to name a couple
of threading techniques you might have otherwise used).
Because the Ping class obviously has to use some sort of network resource,
I'm assuming that you'd want to create a fixed number of Ping instances
and reuse them as they complete. But if it turns out I'm wrong about
that, you might even be able to get away with just creating a whole new
Ping instance for each ping attempt.
Pete