From cc37cf55c02da9e49eab9859ed72f146dee6f635 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期一, 11 九月 2023 14:17:55 +0800
Subject: [PATCH] Merge branch 'Dev-Branch' into wjc

---
 HDL_ON/UI/UI2/FuntionControlView/Light/DimmerPageBLL.cs |  120 +++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 83 insertions(+), 37 deletions(-)

diff --git a/HDL_ON/UI/UI2/FuntionControlView/Light/DimmerPageBLL.cs b/HDL_ON/UI/UI2/FuntionControlView/Light/DimmerPageBLL.cs
index 4a6cf52..765396b 100644
--- a/HDL_ON/UI/UI2/FuntionControlView/Light/DimmerPageBLL.cs
+++ b/HDL_ON/UI/UI2/FuntionControlView/Light/DimmerPageBLL.cs
@@ -8,40 +8,87 @@
     public partial class DimmerPage
     {
         /// <summary>
+        /// 閫氱煡鏇存柊鐣岄潰鐨勬椂闂�
+        /// </summary>
+        DateTime notiyUpdateTime = DateTime.MinValue;
+        System.Threading.Thread updateUiThread;
+        object lockObj = new object();
+        
+        /// <summary>
         /// 鏇存柊鍔熻兘鐘舵��
         /// </summary>
         public static void UpdataStates(Function updataTemp)
         {
-            Application.RunOnMainThread((() =>
+            if (bodyView == null)
             {
-                try
+                return;
+            }
+            lock (bodyView.lockObj)
+            {
+                MainPage.Log($"鏀跺埌鏇存柊" + DateTime.Now.Ticks);
+                bodyView.notiyUpdateTime = DateTime.Now;
+                if (bodyView.updateUiThread == null)
                 {
-                    if (bodyView == null)
-                        return;
-                    if (updataTemp.spk == bodyView.function.spk && updataTemp.sid == bodyView.function.sid)
+                    bodyView.updateUiThread = new System.Threading.Thread(() =>
                     {
-                        bodyView.btnBrightnessText.Text = updataTemp.GetAttrState(FunctionAttributeKey.Brightness) + "%";
-                        if (updataTemp.trait_on_off.curValue.ToString() == "on")
+                        while (true)
                         {
-                            bodyView.dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
-                            if (!bodyView.onDimmerBar)
+                            System.Threading.Thread.Sleep(1500);
+                            if (bodyView == null)
                             {
-                                bodyView.dimmerBar.Progress = Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness));
-                                bodyView.btnBrightnessText.Y = ((100 - Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(288 - 16 - 16) / 100) + Application.GetRealWidth(40);
+                                return;
+                            }
+                            if (DateTime.Now.AddMilliseconds(-1500) > bodyView.notiyUpdateTime)
+                            {
+                                MainPage.Log("娌℃湁鏂版暟鎹紝鏇存柊UI");
+                                break;
+                            }
+                            else
+                            {
+                                MainPage.Log("鏈夋柊鏁版嵁锛岀户缁瓑寰�");
                             }
                         }
-                        else
-                        {
-                            bodyView.dimmerBar.SetProgressBarColors(CSS_Color.DividingLineColor, CSS_Color.DividingLineColor);
-                        }
-                        bodyView.btnSwitch.IsSelected = updataTemp.trait_on_off.curValue.ToString() == "on";
-                    }
+
+                        Application.RunOnMainThread(() =>{
+                            try
+                            {
+                                if (bodyView == null)
+                                    return;
+                                if (updataTemp.spk == bodyView.function.spk && updataTemp.sid == bodyView.function.sid)
+                                {
+                                    bodyView.btnBrightnessText.Text = updataTemp.GetAttrState(FunctionAttributeKey.Brightness) + "%";
+                                    if (updataTemp.trait_on_off.curValue.ToString() == "on")
+                                    {
+                                        bodyView.dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
+                                        if (!bodyView.onDimmerBar)
+                                        {
+                                            bodyView.dimmerBar.Progress = Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness));
+                                            bodyView.btnBrightnessText.Y = ((100 - Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(288 - 16 - 16) / 100) + Application.GetRealWidth(40);
+                                        }
+                                    }
+                                    else
+                                    {
+                                        bodyView.dimmerBar.SetProgressBarColors(CSS_Color.DividingLineColor, CSS_Color.DividingLineColor);
+                                    }
+                                    bodyView.btnSwitch.IsSelected = updataTemp.trait_on_off.curValue.ToString() == "on";
+                                }
+                            }
+                            catch (Exception ex)
+                            {
+                                MainPage.Log($"{bodyView.GetType().Name} UpdataStates error : {ex.Message}");
+                            }
+                            finally
+                            {
+                                bodyView.updateUiThread = null;
+                            }
+                        });
+
+
+                        bodyView.updateUiThread.IsBackground = true;
+                        bodyView.updateUiThread.Start();
+                    });
                 }
-                catch (Exception ex)
-                {
-                    MainPage.Log($"{bodyView.GetType().Name } UpdataStates error : {ex.Message}");
-                }
-            }));
+            }
         }
 
         void LoadEventList()
@@ -117,7 +164,6 @@
                 //20201223 鍒犻櫎婊戝姩鍙戦�佸懡浠わ紝闃叉鎺т欢璺冲姩
                 dimmerBar.OnProgressChangedEvent = (sender, e) =>
                 {
-                   
                     if (!btnSwitch.IsSelected)
                     {
                         dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
@@ -132,20 +178,20 @@
                         d.Add(FunctionAttributeKey.Brightness, e.ToString());
                         Control.Ins.SendWriteCommand(function, d);
                     }
-                    else
-                    {
-                        if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
-                        {
-                            function.refreshTime = DateTime.Now;
-                            new System.Threading.Thread(() =>
-                            {
-                                System.Collections.Generic.Dictionary<string, string> dic = new System.Collections.Generic.Dictionary<string, string>();
-                                dic.Add(FunctionAttributeKey.Brightness, e.ToString());
-                                Control.Ins.SendWriteCommand(function, dic);
-                            })
-                            { IsBackground = true }.Start();
-                        }
-                    }
+                    //else
+                    //{
+                    //    if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
+                    //    {
+                    //        function.refreshTime = DateTime.Now;
+                    //        new System.Threading.Thread(() =>
+                    //        {
+                    //            System.Collections.Generic.Dictionary<string, string> dic = new System.Collections.Generic.Dictionary<string, string>();
+                    //            dic.Add(FunctionAttributeKey.Brightness, e.ToString());
+                    //            Control.Ins.SendWriteCommand(function, dic);
+                    //        })
+                    //        { IsBackground = true }.Start();
+                    //    }
+                    //}
                     btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(288 - 16 - 16) / 100) + Application.GetRealWidth(40);
                     btnBrightnessText.Text = dimmerBar.Progress + "%";
                 };

--
Gitblit v1.8.0