multithreaded - advice on how to structure for this task

J

James

Hello,

goal:
A one form windows app that is a ping utility. It will support being able to
simultaneously ping multiple targets (not likely more than 10 at a time).

My plan at the moment:
- text box and button to add target IP to a listView control

- listView control will maintain list of current targets and their status
(up or down), and message such as 'timed out' etc..

- buttons under the listview control to be able to: pause or resume a ping
to the selected target, or of course stop/remove the target from the list

- each ping session will occur in its own explicitly created thread,
synchronous send method of the the networkInformation's ping class will be
used for pinging.

- use the listview's control.Invoke method to update it's contents from the
other threads

QUESTIONS:

How should I go about implementing the pause, resume, etc.. buttons? I'm
thinking specifically here about the mutlithreaded scenario at work here.

1. my first thought was synchronizing access to an array or collection
object of some kind so that each ping session (each on its own thread) has a
way to know if it should continue or stop, or exit etc.. At the begining it
would first add itself to this object then check it to know if it should
keep going or not. I would synchronize with the lock statement. However each
ping session would need to check on this object before executing each
iteration/ping to see if it should continue or not... I'm thinking I would
have to many threads trying to access this one object to often and have
issues. Yes/no?

2. then I thought about using events? I have never done this but in concept
(and some uneducated assumptions) I'm thinking it would be better... as each
ping target gets added to the list it creates/registers (not sure of correct
terminology there) an event handler for itself... then when that particular
target is selected in the list the one 'pause' button, for example, would
fire that targets specific event? I'm thinking that way there is no checking
that needs to be done of every ping iteration and therefore no contention
for that one shared object?

I'm not sure I am even experienced enough in this kind of code that I'm
asking this appropriately.

any input is apprecated and accompanying skeleton code demonstrating the
structure would be extremely helpful.

thank you!
 
J

James

Hi Peter,

I had to put this on hold as I had another issue I had to deal with.... just
getting back to this now and checked up on this post. Thank you very much
for the detailed information. I really appreciate it.

thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top