From 489f97fe705b17fa0d370102563cbb7ded2ede69 Mon Sep 17 00:00:00 2001 From: Michele Cattafesta Date: Fri, 2 Oct 2015 18:35:27 +0200 Subject: [PATCH] IsAvailable disposes Ping properly (Issue #32). Signed-off-by: Michele Cattafesta --- S7.Net/PLC.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/S7.Net/PLC.cs b/S7.Net/PLC.cs index f9715cc..2a29fc3 100644 --- a/S7.Net/PLC.cs +++ b/S7.Net/PLC.cs @@ -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; + } } }