I'm having some trouble with SendAsync method when passing an invalid IP - 0.0.0.51
Problem is, the Call back method (pingSender_PingCompleted) does not even get invoked. I do not see any errors what so ever.
IPAddress.TypeParse finds this IP as a "valid" IP.
Here is my code; please let me know what I'm not seeing here.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program c = new Program();
try
{
c.PingStore("0.0.0.51");
Console.WriteLine("Pinged without exceptions");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void PingStore(string ipAddress)
{
Ping pingSender = new Ping();
pingSender.PingCompleted += new PingCompletedEventHandler(pingSender_PingCompleted);
pingSender.SendAsync(ipAddress, null);
}
private void pingSender_PingCompleted(object sender, PingCompletedEventArgs e)
{
Console.WriteLine("PingCompleted invoked. continue to be happy");
}
}
}
Please note that I can't:
Have any kind of control over what comes through ipAddress
Complicate my code by using Regex