Exemple #1
0
            public void PingIp()
            {
                PingType pingType = new PingType();

                pingType.index = index;
                pingType.ip    = ip;
                Ping ping = new Ping();

                for (int i = 0; i < 50; i++)
                {
                    try
                    {
                        PingReply pingReply = ping.Send(ip);
                        pingType.delay = (int)pingReply.RoundtripTime;
                        if (pingType.delay == 0)
                        {
                            pingType.msg     = pingReply.Status.ToString();
                            pingType.success = false;
                        }
                        else
                        {
                            pingType.msg     = pingReply.Status.ToString();
                            pingType.success = true;
                        }
                    }
                    catch (Exception e)
                    {
                        pingType.msg     = e.Message;
                        pingType.success = false;
                        //throw;
                    }
                    callBack(pingType);
                    //Thread.Sleep(100);
                }
            }
Exemple #2
0
        private void ThreadCallBack(PingType pingType)
        {
            int i     = pingType.index;
            int delay = pingType.delay;

            speedData[i].ping_times += 1;
            if (pingType.success == true)
            {
                speedData[i].delay_last    = delay;
                speedData[i].delay_average = (speedData[i].delay_average + delay) / 2;
                int min = 0;
                if (speedData[i].delay_min == 0 && delay > 0)
                {
                    min = delay;
                }
                else
                {
                    min = Math.Min(speedData[i].delay_min, delay);
                }
                speedData[i].delay_min           = min;
                speedData[i].delay_max           = Math.Max(speedData[i].delay_max, delay);
                speedData[i].ping_times_success += 1;
            }
            else
            {
                speedData[i].ping_times_faild += 1;
            }
        }