IsAvailable disposes Ping properly (Issue #32).

Signed-off-by: Michele Cattafesta <michele.cattafesta@mesta-automation.com>
This commit is contained in:
Michele Cattafesta
2015-10-02 18:35:27 +02:00
parent 92dd158698
commit 489f97fe70

View File

@@ -26,9 +26,19 @@ namespace S7.Net
{
get
{
Ping ping = new Ping();
PingReply result = ping.Send(IP);
return result != null && result.Status == IPStatus.Success;
using (Ping ping = new Ping())
{
PingReply result;
try
{
result = ping.Send(IP);
}
catch (PingException)
{
result = null;
}
return result != null && result.Status == IPStatus.Success;
}
}
}