Re: example wtih multithreading and ping
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 23 Jan 2008 00:57:18 -0800
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
.
- Follow-Ups:
- Re: example wtih multithreading and ping
- From: Heike Pertzel
- Re: example wtih multithreading and ping
- From: Heike Pertzel
- Re: example wtih multithreading and ping
- References:
- example wtih multithreading and ping
- From: Heike Pertzel
- Re: example wtih multithreading and ping
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: example wtih multithreading and ping
- From: Heike Pertzel
- example wtih multithreading and ping
- Prev by Date: ListBox empy using Data Binding, instead normally works
- Next by Date: Re: Called ServiceBase.Run(), but never receive OnStart()?
- Previous by thread: Re: example wtih multithreading and ping
- Next by thread: Re: example wtih multithreading and ping
- Index(es):
Relevant Pages
|