コード例 #1
0
        private void Pingtest(object obj)
        {
            MutipleThreadResetEvent resetEvent = (MutipleThreadResetEvent)obj;
            IPAddress   myIP       = IPAddress.Parse("120.77.134.57");
            Ping        pingSender = new Ping();
            PingOptions options    = new PingOptions();

            options.DontFragment = true;
            string data = "F**k You Gaode";

            byte[] buffer  = Encoding.ASCII.GetBytes(data);
            int    timeout = 3000;

            for (int a = 0; a <= 4; a++)
            {
                try
                {
                    PingReply reply = pingSender.Send(myIP, timeout, buffer, options);
                    if (reply.Status == IPStatus.Success)
                    {
                        SetTextBox("服务器连接成功,网络延迟为:" + reply.RoundtripTime + "\r\n");
                        pingtestpass = true;
                        resetEvent.SetOne();
                        return;
                    }
                    else
                    {
                        SetTextBox("第" + (a + 1).ToString() + "次连接地图更新服务器失败:" + reply.Status.ToString() + "\r\n");
                        if (a == 4)
                        {
                            SetTextBox("地图服务器无法连接。请检查网络状态。\r\n");
                            pingtestpass = false;
                            resetEvent.SetOne();
                            return;
                        }
                    }
                }
                catch (Exception err)
                {
                    SetTextBox("网络出错:" + err.Message + "\r\n");
                }
            }
            pingtestpass = false;
            resetEvent.SetOne();
            return;
        }
コード例 #2
0
        private void Update_Position(object param)
        {
            bool notpass = true;

            object[] objArr = (object[])param;
            int      i      = (int)objArr[0];
            MutipleThreadResetEvent countdown = (MutipleThreadResetEvent)objArr[1];

            while (notpass)
            {
                string getjson1 = DoGetPosition(citys[i]);
                try
                {
                    posarr[i].x = Convert.ToDouble(GetLng(getjson1));
                    posarr[i].y = Convert.ToDouble(GetLat(getjson1));
                    if (i % 50 == 0)
                    {
                        SetProgressBar(3 + i / 100);
                    }
                    if (!richTextBox1.IsDisposed)
                    {
                        SetTextBox(DataBase_city[i] + " " + posarr[i].x + " " + posarr[i].y + "\r\n");
                    }
                    notpass = false;
                }
                catch (Exception err)
                {
                    if (!richTextBox1.IsDisposed)
                    {
                        SetTextBox(DataBase_city[i] + " " + err.Message + "\r\n");
                    }
                    notpass = true;
                }
            }
            countdown.SetOne();
        }
コード例 #3
0
 private void Update_Distance(object param)
 {
     try
     {
         if (citys == null)
         {
             return;
         }
         if (DistanceArray == null)
         {
             return;
         }
         if (richTextBox1.IsDisposed)
         {
             return;
         }
         object[] objArr = (object[])param;
         int      i      = (int)objArr[0];
         int      j      = (int)objArr[1];
         MutipleThreadResetEvent countdown = (MutipleThreadResetEvent)objArr[2];
         if (richTextBox1.IsDisposed)
         {
             countdown.SetOne(); return;
         }
         if (citys == null)
         {
             countdown.SetOne(); return;
         }
         if (DistanceArray == null)
         {
             countdown.SetOne(); return;
         }
         string sstr = DoGetDistance(i, j);
         if (richTextBox1.IsDisposed)
         {
             countdown.SetOne(); return;
         }
         if (DistanceArray == null)
         {
             countdown.SetOne(); return;
         }
         else if ((sstr == "返回数据为空!" || sstr == "返回数据出错!") && DistanceArray != null)
         {
             passthrough = false; DistanceArray[i, j] = DistanceArray[j, i] = 0;
         }
         else if (sstr != "返回数据为空!" && sstr != "返回数据出错!" && DistanceArray != null)
         {
             DistanceArray[i, j] = DistanceArray[j, i] = Convert.ToInt32(sstr);
         }
         else
         {
             passthrough = false; countdown.SetOne(); return;
         }
         if (!richTextBox1.IsDisposed)
         {
             SetTextBox(i.ToString() + ":" + citys[i] + "<-------->" + j.ToString() + ":" + citys[j] + "  " + sstr + "\r\n");
         }
         countdown.SetOne();
         return;
     }
     catch (Exception err)
     {
         MessageBox.Show(err.Message, "界面更新出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }