public override Task <PingReplyWrapper> SendPingAsync(string hostnameOrAddress, TimeSpan timeout) { var factory = new TaskFactory <PingReplyWrapper>(); _task = factory.StartNew(() => { _ping.PingTimeout = (int)timeout.TotalMilliseconds; var result = _ping.PingHost(hostnameOrAddress); var reply = new PingReplyWrapper { RoundtripTime = result.AverageTime, Status = result.PingResult == BS.Utilities.PingResponseType.Ok ? System.Net.NetworkInformation.IPStatus.Success : System.Net.NetworkInformation.IPStatus.IcmpError }; return(reply); }); return(_task); }
public override Task <PingReplyWrapper> SendPingAsync(string hostnameOrAddress, TimeSpan timeout) { ensureNotDisposed(); var factory = new TaskFactory <PingReplyWrapper>(); _task = factory.StartNew(() => { var result = _ping.Send(hostnameOrAddress, timeout); var reply = new PingReplyWrapper { RoundtripTime = result != TimeSpan.MaxValue ? (long)result.TotalMilliseconds : 0, Status = result != TimeSpan.MaxValue ? System.Net.NetworkInformation.IPStatus.Success : System.Net.NetworkInformation.IPStatus.IcmpError }; return(reply); }); return(_task); }