Mercurial > servermonitor
diff ServerMonitor/Objects/Checks/PingCheck.cs @ 17:68d7834dc28e
More comments.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Sat, 25 May 2019 15:14:26 -0400 |
parents | 453ecc1ed9ea |
children |
line wrap: on
line diff
--- a/ServerMonitor/Objects/Checks/PingCheck.cs Tue Apr 30 20:40:58 2019 -0400 +++ b/ServerMonitor/Objects/Checks/PingCheck.cs Sat May 25 15:14:26 2019 -0400 @@ -1,17 +1,15 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; +using System.ComponentModel; using System.Net.NetworkInformation; -using System.Text; using System.Threading; using System.Threading.Tasks; namespace ServerMonitorApp { + /// <summary>Checks that a server responds to ping.</summary> [DisplayName("Ping check"), Description("Check if the server responds to a ping request"), DisplayWeight(0)] public class PingCheck : Check { + /// <summary>Sends a ping and waits for a response.</summary> protected async override Task<CheckResult> ExecuteCheckAsync(CancellationToken token) { using (Ping ping = new Ping()) @@ -29,28 +27,6 @@ return Fail(e); } } - - // Cancellable version that doesn't actulaly work - // might be useful as a TaskCompletionSource example though - // - //TaskCompletionSource<CheckResult> tcs = new TaskCompletionSource<CheckResult - // - //using (Ping ping = new Ping()) - //{ - // token.Register(ping.SendAsyncCancel); - // ping.PingCompleted += (sender, e) => - // { - // if (e.Error != null) - // tcs.SetResult(Fail("Ping failed: " + e.Error.GetBaseException().Message)); - // else if (e.Reply.Status != IPStatus.Success) - // tcs.SetResult(Fail("Ping failed: " + e.Reply.Status.ToString())); - // else - // tcs.SetResult(Pass("Ping completed in " + e.Reply.RoundtripTime + "ms")); - // }; - // ping.SendAsync(Server.Host, Timeout, null); - //} - - //return tcs.Task; } } }