Exemplo n.º 1
0
 // Constructor.
 public PingSender()
 {
     this._ping                = new Ping();
     this._options             = new PingOptions(255, true);
     this._waiter              = new AutoResetEvent(false);
     this.HostName             = "www.google.com";
     this.TimeOut              = 3000;
     this.PacketSize           = 32;
     this.Results              = new PingResultList(20);
     this.History              = new PingHistory();
     this._ping.PingCompleted += PingCompletedCallback;
 }
Exemplo n.º 2
0
        private void PingSender_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            DateTime       date    = DateTime.Now;
            PingHistory    history = this.pingSender.History;
            PingResultList results = this.pingSender.Results;
            PingReply      reply   = e.Reply;

            if (reply != null)
            {
                if (reply.Status > 0)
                {
                    this.chart.Series["Time"].Points.AddXY(history.SendPackets, 0);
                    this.tableResults.Rows.Add(date, this.StatusError(reply.Status));
                }
                else
                {
                    this.chart.Series["Time"].Points.AddXY(history.SendPackets, reply.RoundtripTime);
                    this.tableResults.Rows.Add(date, reply.Address, reply.RoundtripTime, reply.Buffer.Length, reply.Options.Ttl);
                }
            }
            else
            {
                this.chart.Series["Time"].Points.AddXY(history.SendPackets, 0);
                this.tableResults.Rows.Add(date, this.StatusError(IPStatus.Unknown));
            }
            if (this.chart.Series["Time"].Points.Count > 20)
            {
                this.chart.Series["Time"].Points.RemoveAt(0);
                this.chart.ChartAreas["ChartArea1"].AxisX.Maximum++;
                this.chart.ChartAreas["ChartArea1"].AxisX.Minimum++;
                this.chart.ChartAreas["ChartArea1"].RecalculateAxesScale();
            }
            if (this.tableResults.Rows.Count > 20)
            {
                this.tableResults.Rows.RemoveAt(0);
            }
            this.tbTimeMin.Text             = history.TimeMin.ToString() + "ms";
            this.tbLastTimeMin.Text         = results.TimeMin.ToString() + "ms";
            this.tbTimeMax.Text             = history.TimeMax.ToString() + "ms";
            this.tbLastTimeMax.Text         = results.TimeMax.ToString() + "ms";
            this.tbTimeAverage.Text         = history.TimeAverage.ToString("F0") + "ms";
            this.tbLastTimeAverage.Text     = results.TimeAverage.ToString("F0") + "ms";
            this.tbSendPackets.Text         = history.SendPackets.ToString();
            this.tbLastSendPackets.Text     = results.SendPackets.ToString();
            this.tbReceivedPackets.Text     = history.ReceivedPackets.ToString();
            this.tbLastReceivedPackets.Text = results.ReceivedPackets.ToString();
            this.tbLostPackets.Text         = history.LostPackets.ToString() + " (" + (history.LostPacketsRatio * 100).ToString("F0") + "%)";
            this.tbLastLostPackets.Text     = results.LostPackets.ToString() + " (" + (results.LostPacketsRatio * 100).ToString("F0") + "%)";
            this.DisplayStabilityStatus(results.LostPacketsRatio);
            this.DisplayPingStatus(results.TimeAverage, results.LostPacketsRatio);
        }