Пример #1
0
        private void PingResult(object sender, PingCompletedEventArgs e)
        {
            var pingReplyArrivedEventArgs = new PingReplyArrivedEventArgs(e.Reply, e.Cancelled, e.Error);

            PingReplyArrived?.Invoke(this, pingReplyArrivedEventArgs);
            ((IDisposable)ping).Dispose();
        }
Пример #2
0
        public static PingReplyMessage PingDiagnosticResult(PingReplyArrivedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.PingReply == null || e.PingReply.Status != IPStatus.Success)
            {
                return(new PingReplyMessage(false, "Ping failed", e.StatusMessage));
            }

            return(new PingReplyMessage(true, "Ping successful", $"Ping reply arrived in {e.PingReply.RoundtripTime} ms"));
        }