…that is the question!
An interesting thread over on vbforums.com brought up the topic of using a ping to condition whether or not to continue performing a network task. One argument is that you want to see if there is a viable connection to the remote device before you try to do anything to/with it. The other argument is, why introduce the bandwidth overhead of a ping command when you can just attempt the task and handle the exception if it fails.
Both interesting perspectives, and personally, I am in the boat that says ping first, task next. I can understand both sides though and have posted this for both sides to discuss.
EDIT: Here is a short code snippet to test the pre-ping theory. Code is provided by @dbasnett and is a great example of the time involved with a ping request.
Dim srvrName As String = "mail.foo.bar" Dim smtpserver As New Net.Mail.SmtpClient(srvrName) Dim mailMessage As System.Net.Mail.MailMessage Private Sub foobar() 'The argument for PING Try If My.Computer.Network.Ping(srvrName) Then smtpserver.Send("firstname.lastname@example.org", "email@example.com", "jjj", "jdfo") MessageBox.Show("Mail sent successfully") Else MessageBox.Show("Could not ping someaddress") End If Catch ex As Exception MessageBox.Show(ex.Message) 'Exit Sub End Try 'The opposing view - the one I support Try smtpserver.Send("firstname.lastname@example.org", "email@example.com", "jjj", "jdfo") MessageBox.Show("Mail sent successfully") Catch ex As Exception If Not ex.InnerException Is Nothing Then MessageBox.Show(ex.InnerException.Message) Else MessageBox.Show("Failure sending mail") End If 'Exit Sub End Try End Sub