asynchronously or synchronously?  
Author Message
Jassim Rahma





PostPosted: Visual C# General, asynchronously or synchronously? Top

I have seen the Ping code in this link:

http://www.hide-link.com/

and i would like to know what is the difference between asynchronously ping and synchronously ping




Visual C#9  
 
 
Andreas Johansson





PostPosted: Visual C# General, asynchronously or synchronously? Top

Synchron is similar to that you call a friend and ask him check if the computer is turned on and he immediatly go and check it while you wait for him to get back and tell you the answer. In other ways, you ask for something and wait for it to be done.

Asynchron would be that you call your friend and ask him to check if the computer is turned on and that he call back as soon as he has the result, you hang up and start doing something else. After a while he gets back to you and you can do what you need to do know that you have the response. In other words, you ask something and can continue do something else while you wait for the response as you will get notified as soon as there is a result for you.

In the case of the ping, it does the same thing but the difference is how your code waits for the synchron to complete while the asynchron will notify (raise an event, call a delegate/callback) once it has a result.



 
 
nobugz





PostPosted: Visual C# General, asynchronously or synchronously? Top

A synchronous ping, activated by Send(), blocks your program until a response is received. An asynchronous ping, activated by SendAsync(), keeps your program running; you'll need a PingCompleted event handler to know the outcome.