Ejemplo n.º 1
0
        /// <summary>
        /// New thread used to ping the selected server
        /// and calculate statistics
        /// </summary>
        private void ThreadAction()
        {
            Console.WriteLine("Thread Started");

            PingQueue = new CustomQueue(100);

            if (!Uri.IsWellFormedUriString(URL, UriKind.RelativeOrAbsolute))
            {
                Console.WriteLine("URL Failed");
                return;
            }

            int Pings = 0;

            while (!threadStop)
            {
                Ping      p  = new Ping();
                PingReply pr = p.Send(URL);

                AveragePings.Add(pr.RoundtripTime);

                uiContext.Send(x => PingQueue.AddToQueue(pr.RoundtripTime.ToString()), null);
                uiContext.Send(x => dataPoints.AddToQueue((double)pr.RoundtripTime), null);

                Average = GetAverage(AveragePings);
                Status  = pr.Status.ToString();

                if (pr.RoundtripTime > 500)
                {
                    uiContext.Send(x => Messenger.Default.Send("HighPing", "Toast"), null);
                }
                if (Status != "Success")
                {
                    uiContext.Send(x => Messenger.Default.Send("Failure", "Toast"), null);
                }

                Pings++;

                PingsSent = "Pings Sent: " + Pings.ToString();

                Thread.Sleep(PingInterval * 1000);
            }
            Console.WriteLine("Thread Stopped");
        }