Re: example wtih multithreading and ping

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Wed, 23 Jan 2008 00:10:32 -0800, Heike Pertzel <HPNews@xxxxxxxx> wrote:

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
.



Relevant Pages

  • Re: example wtih multithreading and ping
    ... You can only have one uncompleted ping per Ping instance, ... Because the Ping class obviously has to use some sort of network resource, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: example wtih multithreading and ping
    ... You can only have one uncompleted ping per Ping instance, ... Because the Ping class obviously has to use some sort of network resource, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Mshome is not accessible
    ... Windows Network, and select the workgroup I get: ... Mshome is not accessible. ... All computers are running Windows XP SP2 and are members of the MSHOME ... Computer A can ping using ping hom100fr001. ...
    (microsoft.public.windowsxp.network_web)
  • network slowness/freez-up since update 10/11
    ... network problems: first the network is slow (even within a few ... network - but not the rest of the system - just locks up (can't ping ... OHCI version 1.0, legacy support ... <Parallel port bus> on ppc0 ...
    (freebsd-current)
  • network slowness/freez-up since update 10/11
    ... network problems: first the network is slow (even within a few ... network - but not the rest of the system - just locks up (can't ping ... OHCI version 1.0, legacy support ... <Parallel port bus> on ppc0 ...
    (freebsd-current)