private void pingSender_PingCompleted(object sender, PingCompletedEventArgs e) { try { if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = "Ping Completed"; } ((AutoResetEvent)e.UserState).Set(); if (e.Reply.Status == IPStatus.Success) { lock (this.threadLocker) { PingReplyData pd = new PingReplyData( this.counter++, "Reply from: ", this.hostName, this.destination, e.Reply.Buffer.Length, e.Reply.Options.Ttl, e.Reply.RoundtripTime); lock (this.pingList) { this.pingList.Add(pd); } this.Invoke(this.DoUpdateForm); this.pingReady = true; } } else if (!e.Cancelled) { String status = String.Empty; switch (e.Reply.Status) { case IPStatus.TimedOut: status = "Request timed out."; break; case IPStatus.DestinationHostUnreachable: status = "Destination host unreachable."; break; } lock (this.threadLocker) { this.pingSender.SendAsyncCancel(); PingReplyData pd = new PingReplyData( this.counter++, status, String.Empty, String.Empty, 0, 0, 0); lock (this.pingList) { this.pingList.Add(pd); } this.Invoke(this.DoUpdateForm); this.pingReady = true; } } } catch (Exception ex) { Logging.Info("Error on Ping.PingCompleted", ex); } finally { ((AutoResetEvent)e.UserState).Set(); } }
private void pingSender_PingCompleted(object sender, PingCompletedEventArgs e) { try { if (Thread.CurrentThread.Name == null) Thread.CurrentThread.Name = "Ping Completed"; ((AutoResetEvent)e.UserState).Set(); if (e.Reply.Status == IPStatus.Success) { lock (this.threadLocker) { PingReplyData pd = new PingReplyData( this.counter++, "Reply from: ", this.hostName, this.destination, e.Reply.Buffer.Length, e.Reply.Options.Ttl, e.Reply.RoundtripTime); lock (this.pingList) { this.pingList.Add(pd); } this.Invoke(this.DoUpdateForm); this.pingReady = true; } } else if (!e.Cancelled) { String status = String.Empty; switch (e.Reply.Status) { case IPStatus.TimedOut: status = "Request timed out."; break; case IPStatus.DestinationHostUnreachable: status = "Destination host unreachable."; break; } lock (this.threadLocker) { this.pingSender.SendAsyncCancel(); PingReplyData pd = new PingReplyData( this.counter++, status, String.Empty, String.Empty, 0, 0, 0); lock (this.pingList) { this.pingList.Add(pd); } this.Invoke(this.DoUpdateForm); this.pingReady = true; } } } catch (Exception ex) { Logging.Info("Error on Ping.PingCompleted", ex); } finally { ((AutoResetEvent)e.UserState).Set(); } }