not the time for the async method?

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello,

I know I can't do the following but, one, I was wondering why? and two, what
do I do for sending multiple pings? or a continuous ping that the user stops
with a button click? Do I need to spawn my own thread and call the
synchronous method instead of the async one?

for (int i = 0; i < 11; i++)
{
pingSender.SendAsync(txtIP.Text.Trim(), timeout, buffer, options,
waiter);
}
 
I'm sorry, I should clarify: I'm using the ping class in the
system.net.networkinformation namespace. 'pingSender' below is an instance
of that class. Also, I think I recall what I am supposed to do now, I did a
multithreaded thing a while back but don't do this frequently enough to
remember the details... so let me know if I'm wrong here. I should just call
the async send method again within the callback function? that effectively
creates my loop of calls to ping? And in order to stop it and need a
variable that is accessible to both the calling function and the callback
function to track when the loop should stop, and that variable should be
locked whenever accessed for read/write with the lock statement... yes/no?
 
ok, I did what I just explained in my last reply and it seems to be
working... please let me know if this is the correct approach... even though
I only program on an off and on basis, when I do, I like to follow best
practices as much as possible.

thanks.
 
Back
Top