Esempio n. 1
0
        /// <summary>
        ///     Update form control with new data.
        /// </summary>
        private void UpdateForm()
        {
            PingReplyData data = this.pingList[this.pingList.Count - 1];

            this.dataGridView1.Rows.Add(new object[] { data.Count, data.Status, data.Hostname, data.Destination, data.Bytes, data.TimeToLive, data.RoundTripTime, data.Time });

            if (this.dataGridView1.Rows.Count > 1)
            {
                this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;
            }

            this.UpdateGraph();
        }
Esempio n. 2
0
        private void pingSender_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            if (this.disposing)
                return;

            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,
                            DateTime.Now.ToLongTimeString());

                        lock (this.pingList)
                        {
                            this.pingList.Add(pd);
                        }

						if (!this.IsDisposed && !this.Disposing)
							this.InvokeIfNecessary(() => 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, DateTime.Now.ToLongTimeString());

                        lock (this.pingList)
                        {
                            this.pingList.Add(pd);
                        }
                        
						if (!this.IsDisposed && !this.Disposing)
							this.InvokeIfNecessary(() => this.Invoke(this.DoUpdateForm));
                        this.pingReady = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Info("Error on Ping.PingCompleted", ex);
            }
            finally
            {
                ((AutoResetEvent) e.UserState).Set();
            }
        }
Esempio n. 3
0
        private void pingSender_PingCompleted(object sender, PingCompletedEventArgs e)
        {
            if (this.disposing)
            {
                return;
            }

            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,
                            DateTime.Now.ToLongTimeString());

                        lock (this.pingList)
                        {
                            this.pingList.Add(pd);
                        }

                        if (!this.IsDisposed && !this.Disposing)
                        {
                            this.InvokeIfNecessary(() => 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, DateTime.Now.ToLongTimeString());

                        lock (this.pingList)
                        {
                            this.pingList.Add(pd);
                        }

                        if (!this.IsDisposed && !this.Disposing)
                        {
                            this.InvokeIfNecessary(() => this.Invoke(this.DoUpdateForm));
                        }
                        this.pingReady = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Info("Error on Ping.PingCompleted", ex);
            }
            finally
            {
                ((AutoResetEvent)e.UserState).Set();
            }
        }