黄学彪
2020-07-01 304dca51c28183a9dfc192c6b93ea1c00bdd5d97
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
@@ -30,9 +30,9 @@
        /// </summary>
        private bool newGatewayGetting = false;
        /// <summary>
        /// 网关检测中
        /// 网关搜索中
        /// </summary>
        private string isGatewayChecking = "0";
        private bool isGatewaySearching = true;
        #endregion
@@ -77,6 +77,8 @@
            //初始化连接的假想动画效果
            this.InitConcetionAnimete(picGwImage, btnMsg);
            //开启网关检测的线程
            this.StartCheckGatewayThread();
        }
        /// <summary>
@@ -226,10 +228,6 @@
            string strMsg = btnMsg.Text;
            HdlThreadLogic.Current.RunThread(() =>
            {
                //清空全部列表
                HdlGatewayLogic.Current.ClearAllRealGateway();
                ZigBee.Common.Application.IsSearchingGateway = true;
                int index = 1;
                int maxCount = 120 * 2;
                int timeCount = 120;
@@ -237,36 +235,13 @@
                {
                    System.Threading.Thread.Sleep(500);
                    maxCount--;
                    if (maxCount % 4 == 0)
                    {
                        lock(isGatewayChecking)
                        {
                            if (isGatewayChecking != "1")
                            {
                                isGatewayChecking = "1";
                                HdlThreadLogic.Current.RunThread(async () =>
                                {
                                    //每2秒检测搜索到的网关
                                    await this.CheckZbGatewayAndSetRow();
                                    lock (isGatewayChecking)
                                    {
                                        isGatewayChecking = "0";
                                    }
                                });
                            }
                        }
                    }
                    if (this.newGatewayGetting == true)
                    {
                        //获取得到新网关,则中断线程
                        break;
                    }
                    if (maxCount % 2 == 0)
                    {
                        timeCount--;
                    }
                    if (maxCount <= 0)
                    if (maxCount <= 0 || this.newGatewayGetting == true)
                    {
                        //获取得到新网关,则中断线程
                        break;
                    }
                    Application.RunOnMainThread(() =>
@@ -281,6 +256,9 @@
                        btnMsg.Text = strMsg + timeCount + "s";
                    });
                }
                //搜索结束
                this.isGatewaySearching = false;
                if (maxCount <= 0)
                {
                    HdlThreadLogic.Current.RunMain(() =>
@@ -306,6 +284,42 @@
        #endregion
        #region ■ 网关检测___________________________
        /// <summary>
        /// 开启网关检测的线程
        /// </summary>
        private void StartCheckGatewayThread()
        {
            this.isGatewaySearching = true;
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //清空全部列表
                HdlGatewayLogic.Current.ClearAllRealGateway();
                ZigBee.Common.Application.IsSearchingGateway = true;
                int count = 0;
                while (this.Parent != null && this.isGatewaySearching == true)
                {
                    //每2秒检测搜索到的网关
                    System.Threading.Thread.Sleep(500);
                    count++;
                    if (count < 4)
                    {
                        //主要为了快一点能够中断这个线程
                        continue;
                    }
                    count = 0;
                    await this.CheckZbGatewayAndSetRow();
                    if (this.newGatewayGetting == true)
                    {
                        //获取得到新网关,则中断线程
                        break;
                    }
                }
            });
        }
        /// <summary>
        /// 检测搜索到的网关,然后添加到画面的行里面
@@ -399,7 +413,7 @@
                    this.newGatewayGetting = true;
                }
                if (mode == GatewayBindMode.First)
                if (mode == GatewayBindMode.First || mode == GatewayBindMode.Binded)
                {
                    //我觉得这里需要获取一下新网关的设备列表
                    Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);